本地通知不触发后台获取

Local Notification Not Firing With Background Fetch

谁能看看下面的代码并告诉我为什么本地通知没有触发。我 运行 XCode 中的应用程序并使用调试选项模拟后台获取,但本地通知不会触发。

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
 {
     NSLog(@"performFetchWithCompletionHandler");


UILocalNotification *localNotif = [[UILocalNotification alloc] init];

if (localNotif) {
    localNotif.alertBody = @"Update demo text!";
    localNotif.alertAction = @"OK";
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.fireDate = nil;

    NSLog(@"Local Notification");

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}

//Perform some operation
completionHandler(UIBackgroundFetchResultNewData);
}

是否查询用户允许推送?

if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil];
      [application registerUserNotificationSettings:settings];
    }

不检查设备版本,而是使用下面的代码检查 RespondToSelector:

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