最近调试程序时发现一个bug,在最新的ios9系统下面,如果用
[[UIApplication sharedApplication] scheduleLocalNotification:]
方法去添加一个UILocalNotification,并且这个UILocalNotification的fireDate是第二天的某个时间,那么系统就不会推送这个消息(当天的没有问题)。我是用一个全新的app进行测试的,排除了自己代码造成的问题后,我估计这可能是系统的一个bug,如果有其他人发现了相同的问题,可以给我留言,一起探讨。
我测试的代码如下:
//取消通知,这句可以注释掉,不影响测试
[[UIApplicationsharedApplication] cancelAllLocalNotifications];
//注册通知,这个必须要加上
UIUserNotificationSettings*uns = [UIUserNotificationSettingssettingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound)categories:nil];
[[UIApplicationsharedApplication] registerForRemoteNotifications];
[[UIApplicationsharedApplication] registerUserNotificationSettings:uns];
//添加通知
UILocalNotification*localNotify = [[UILocalNotificationalloc] init];
localNotify.alertTitle=@"测试";
localNotify.alertBody=@"xxxxxxxx";
NSDate*date = [NSDatedateWithTimeIntervalSince1970:1452045600];//2016-1-6 10:00:00
NSTimeZone*zone = [NSTimeZonesystemTimeZone];
localNotify.fireDate= date;
localNotify.timeZone= zone;
localNotify.soundName=UILocalNotificationDefaultSoundName;
[[UIApplicationsharedApplication]scheduleLocalNotification:localNotify];
NSArray*scheduledNotifies = [[UIApplicationsharedApplication] scheduledLocalNotifications];
NSLog(@"scheduledNotifies = %@",scheduledNotifies);