问题
My app implements the new iOS 10 rich push NotificationService extension.
Everything works as expected on iOS 10, but I also want to support pre iOS 10 devices - of course not rich push, but just regular push. When lowering the deployment target in Xcode to e.g. 8.0 or 9.0 and trying to run on an older simulator or device i get the following errors:
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.
I couldn't find anything officially by Apple stating that your app will only run on iOS 10+ once you add a Service Extension - can someone confirm that?
回答1:
Bhavuk Jain is talking about how to support notification on older ios but doesn't solve the LaunchServicesError. To solve this you need to go to your extension target -> General -> Set Deployment Target (10.0 for this case) under Deployment Info.
回答2:
Firstly Initialize the notification services:
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)
}
}
If successfully registered for remote notifications, this will be called for all the devices:
optional public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
For iOS 10 only, to handle remote notifications:
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
}
For devices below iOS 10:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
}
回答3:
change status of frameworks to optional . when it is required some frameworks not work by ios 9. enter image description here
来源:https://stackoverflow.com/questions/40412905/how-to-run-app-with-unnotificationserviceextension-on-pre-ios-10