1

我的應用程序實現了新的iOS 10豐富的推送NotificationService擴展。如何在iOS 10前使用UNNotificationServiceExtension運行應用程序?

所有功能都可以在iOS 10上按預期工作,但我也想支持iOS 10以前的設備 - 當然不是富有推動性,而只是定期推送。將Xcode中的部署目標降至例如8.0或9.0,並試圖在舊的模擬器或設備我得到以下運行錯誤:

Simulator: The operation couldn’t be completed. (LaunchServicesError error 0.) 
Device: This app contains an app extension that specifies an extension point identifier that is not supported on this version of iOS for the value of the NSExtensionPointIdentifier key in its Info.plist. 

我無法通過蘋果官方發現了什麼,說明你的應用程序只能在iOS上運行10+,一旦你加入服務延期 - 有人可以確認嗎?

+0

您需要爲ios10下面的設備實現UIUserNotifications。 –

+0

@ bhavuk-jain那麼我該怎麼做?你有任何更多的細節或鏈接嗎? –

回答

3

Bhavuk耆那是在談論如何支持通知在舊的IOS,但並沒有解決LaunchServicesError。要解決這個問題,您需要在部署信息下進入您的擴展目標 - >常規 - >設置部署目標(此例爲10.0)。

2

首先初始化通知服務:

func initializeNotificationServices() -> Void { 


     if #available(iOS 10.0, *) { 


      let center = UNUserNotificationCenter.current() 
      center.delegate = self 
      center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in 

       if granted { 
        UIApplication.shared.registerForRemoteNotifications() 
       } 

      } 
     }else { 

      let settings = UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil) 
      UIApplication.shared.registerUserNotificationSettings(settings) 
     } 

    } 

如果成功註冊了遠程通知,這將爲所有設備被稱爲

optional public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) 

對於iOS 10只,處理遠程通知:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) { 

     let userInfo = response.notification.request.content.userInfo 

     notificationReceived(userInfo: userInfo, application: nil) 
    } 

    @available(iOS 10.0, *) 
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 

     let userInfo = notification.request.content.userInfo 

    } 

對於低於iOS的10臺設備:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { 

    } 
相關問題