从iOS 9.x升级到iOS 10后,不会显示本地通知

时间:2016-09-26 14:06:35

标签: ios upgrade uilocalnotification

我正在iOS 9.x上安排本地通知,并将设备升级到iOS 10。

步骤:

  1. 在iOS 9.x中注册本地通知
  2. 在iOS 9.x上安排本地通知
  3. 退出应用
  4. 将设备升级到iOS 10
  5. 等待本地通知显示但无法显示
  6. 以下代码: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;
    

    深入研究日志后,我找到了实例 9月28日18:44:05 iPhone SpringBoard(UserNotificationsServer)[57]:[XXXXXXXXXX]启用通知:0 [authorizationOptions:7]

    请帮忙。提前谢谢。

2 个答案:

答案 0 :(得分:1)

您的此代码不适用于iOS10。 iOS10需要使用以下内容:

UserNotifications framework

答案 1 :(得分:0)