2016-12-05 251 views
0

我使用APNS,它的做工精细iOS上的9 随着iOS10新推API的变化,我不能用于推送通知注册,以便我将下一变化:的iOS推送通知

  1. 启用推送通知目标功能选项卡。
  2. 在didFinishLaunchingWithOptions我们检查操作系统版本和寄存器如下:

    if (SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")) { 
    
        //ios 10 Notifiction 
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; 
        center.delegate = self; 
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ 
         if(!error){ 
          [[UIApplication sharedApplication] registerForRemoteNotifications]; 
          NSLog(@"iOS 10 push notification register successfully "); 
         } 
        }]; 
    } else { 
        // iOS 8-9 Notifications 
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 
    
        [[UIApplication sharedApplication] registerForRemoteNotifications]; 
        NSLog(@"iOS 9 push notification register successfully "); 
    
    } 
    

有了这个改变我管理中的iOS 9和iOS 10进行注册,但我有两个问题:

  1. 一旦我在目标功能选项卡中启用推送通知,推送通知将停止在iOS 9上工作,但注册已成功完成。
  2. 虽然注册成功完成,但推送在iOS 10上完全不起作用。

请记住,如果我关闭推送通知的能力目标选项卡(具有相同的代码)推回在iOS 9工作,但我不能为APNS登记iOS上的10

+0

看到这一次http://stackoverflow.com/questions/39267549/ios-how-to-integrate-push-notification-in-ios-10/39268135#39268135 –

+0

也已经尝试过。在功能选项卡中启用了“推送通知”,添加了UserNotifications框架和UNUserNotificationCenterDelegate,在两个操作系统版本中检查操作系统版本和注册成功完成。问题在于didReceiveRemoteNotification没有调用。我不需要知道通知中的用户操作,但是我实现了didReceiveRemoteNotification:userInfo fetchCompletionHandler以及 –

回答

0
if #available(iOS 8.0, *) { 
     let settings: UIUserNotificationSettings = UIUserNotificationSettings (types: [.alert, .badge, .sound], categories: nil) 
     application.registerUserNotificationSettings(settings) 
     application.registerForRemoteNotifications() 
    }else { 
     let types: UIRemoteNotificationType = [.alert, .badge, .sound] 
     application.registerForRemoteNotifications(matching: types) 
    } 
+0

谢谢但问题不在注册中,它是推送接收 –