本地通知不会出现从iOS版的9.x升级后到iOS 10

问题描述:

我在iOS上的9.x调度本地通知和升级设备到iOS 10.本地通知不会出现从iOS版的9.x升级后到iOS 10

步骤:

  1. 本地注册在iOS中的9.x通知
  2. iOS上的9.x附表本地通知
  3. 退出应用
  4. 设备升级到iOS 10
  5. 等待本地通知露面,但没有出现如下

代码:在didFinsihLaunchingWithOptions

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) 
{ 
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeSound|UIUserNotificationTypeBadge categories:nil]]; 
} 

计划通知代码如下:if (errorRef != NULL) { *errorRef = nil; }

UILocalNotification * localNot = [[UILocalNotification alloc] init]; 
localNot.userInfo = [NSDictionary dictionaryWithObjectsAndKeys: 
        self.reminderId, REMINDER_ID_KEY_IN_LOCAL_NOTIF, 
        aOcc.repeatId, REPETITION_ID_KEY_IN_LOCAL_NOTIF, 
        @(index), SNOOZE_INDEX, 
        nil]; 

localNot.fireDate = [NSDate dateWithTimeInterval:(index * SNOOZE_INTERVAL * 60) sinceDate:aOcc.startTime]; 
localNot.repeatInterval = aOcc.repeatInterval; // NSCalendarUnitWeekOfYear 
localNot.timeZone = aOcc.timeZone; // system timezone 


if (aOcc.messageStr != nil && [aOcc.messageStr length] > 0) 
{ 
    localNot.alertBody = aOcc.messageStr; 
} 

if (self.soundFlag == YES) 
{ 
    if (self.soundFileName != nil && [self.soundFileName length] > 0) 
    { 
     localNot.soundName = [[NSString alloc]initWithFormat:@"%@.%@",self.soundFileName,kDefaultSoundFileExtension]; 
    } 
} 

[[UIApplication sharedApplication] scheduleLocalNotification:localNot]; 

if (aOcc.snoozeArray == nil) 
{ 
    aOcc.snoozeArray = @[localNot]; 
} 
else 
{ 
    aOcc.snoozeArray = [aOcc.snoozeArray arrayByAddingObject:localNot]; 
} 
[self.repetitions setObject:aOcc forKey:aOcc.repeatId]; 
[[RemindersManager sharedInstance] save]; 
return localNot; 

深入探讨日志后,我找到 Sep 28 18:44:05 iPhone SpringBoard(UserNotificationsServer)[57]的实例:[XXXXXXXXXX]启用通知:0 [authorizationOptions:7]

请帮忙。提前致谢。

你的这段代码不适用于iOS10。您需要使用下面的iOS10:

UserNotifications framework