2016-12-05 297 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

謝謝但問題不在註冊中,它是推送接收 –