最近調(diào)試程序時(shí)發(fā)現(xiàn)一個(gè)bug励饵,在最新的ios9系統(tǒng)下面宛官,如果用
[[UIApplication sharedApplication] scheduleLocalNotification:]
方法去添加一個(gè)UILocalNotification,并且這個(gè)UILocalNotification的fireDate是第二天的某個(gè)時(shí)間,那么系統(tǒng)就不會(huì)推送這個(gè)消息(當(dāng)天的沒(méi)有問(wèn)題)顽染。我是用一個(gè)全新的app進(jìn)行測(cè)試的草丧,排除了自己代碼造成的問(wèn)題后狸臣,我估計(jì)這可能是系統(tǒng)的一個(gè)bug,如果有其他人發(fā)現(xiàn)了相同的問(wèn)題昌执,可以給我留言烛亦,一起探討诈泼。
我測(cè)試的代碼如下:
//取消通知,這句可以注釋掉煤禽,不影響測(cè)試
[[UIApplicationsharedApplication] cancelAllLocalNotifications];
//注冊(cè)通知铐达,這個(gè)必須要加上
UIUserNotificationSettings*uns = [UIUserNotificationSettingssettingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound)categories:nil];
[[UIApplicationsharedApplication] registerForRemoteNotifications];
[[UIApplicationsharedApplication] registerUserNotificationSettings:uns];
//添加通知
UILocalNotification*localNotify = [[UILocalNotificationalloc] init];
localNotify.alertTitle=@"測(cè)試";
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);