我UILocalNotification
在 iPhone 中使用 s 来创建警报。当我单击 a 时,会安排警报UIButton
。我的问题是– application:didReceiveLocalNotification:
当我单击此按钮时调用它,即当我创建本地通知时。但是,– application: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")
}