我在iPhone中使用UILocalNotification
來創建鬧鐘。當我點擊UIButton
時,計劃報警。我的問題是,當我點擊此按鈕時,即在創建本地通知時調用– application:didReceiveLocalNotification:
。但是,只有在達到通知時間時才應調用– application:didReceiveLocalNotification:
。我在模擬器和設備上都檢查過它,並得到了相同的結果。任何人都可以幫助我... ...提前感謝。在創建通知後立即調用Appdelegate函數'didreceivelocalnotification'
-(void)createalarm:(NSString *)datend_time:(NSString *)message//creating alarm
{
NSLog(@"created!!!!!!!!!!!!!");
NSString *datestr = datend_time;
NSString *textstr = message;
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"MM/dd/yyyy hh:mm a"];
NSDate *alerttime = [formatter dateFromString:datestr];
UIApplication * app = [UIApplication sharedApplication];
UILocalNotification *notification = [[UILocalNotification alloc] init];
if (notification)
{
notification.fireDate = alerttime;
//notification.timeZone = [NSTimeZone defaultTimeZone];
notification.repeatInterval = 0;
notification.alertBody = textstr;
notification.soundName = UILocalNotificationDefaultSoundName;
[app scheduleLocalNotification:notification];
[app presentLocalNotificationNow:notification];
}
}
-(void)application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification
{
NSLOG(@"delegate called")
}
你的代碼在哪裏? –