1

我的应用程序实现了新的 iOS 10 富推送 NotificationService 扩展。

在 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.

我找不到 Apple 官方提供的任何内容,说明您的应用程序只有在添加服务扩展后才能在 iOS 10+ 上运行 - 有人可以确认吗?

4

3 回答 3

5

Bhavuk Jain 正在讨论如何在旧 ios 上支持通知,但没有解决 LaunchServicesError。要解决此问题,您需要转到部署信息下的扩展目标 -> 常规 -> 设置部署目标(本例中为 10.0)。

于 2016-11-29T21:37:50.597 回答
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]) {

    }
于 2016-11-04T19:06:29.137 回答
-1

将框架的状态更改为可选。当需要时,某些框架不适用于 ios 9。 在此处输入图像描述

于 2017-12-05T13:27:47.340 回答