【问题标题】:Push notification error IOS 8推送通知错误 IOS 8
【发布时间】:2015-05-10 08:07:43
【问题描述】:

我通过推送通知将我的应用程序与 Parse 服务器连接,但问题是我收到错误消息并显示:在 IOS 版本 8.0 中不推荐使用 registerforRemotenotification 类型:请使用注册远程通知并注册用户通知设置。但此代码适用于 IOS8。

谁能帮我写出正确的代码?

    if application.applicationState != UIApplicationState.Background {


        let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
        let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
        var pushPayload = false
        if let options = launchOptions {
            pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
        }
        if (preBackgroundPush || oldPushHandlerOnly || pushPayload) {
            PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
        }
    }
    if application.respondsToSelector("registerUserNotificationSettings:") {
        let userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
        let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    } else {
        let types = UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound
        application.registerForRemoteNotificationTypes(types)
    }


    return true
}
![enter image description here][1]

【问题讨论】:

    标签: swift parse-platform apple-push-notifications


    【解决方案1】:

    取决于你想要什么:

    • 如果您不希望您的应用与 iOS 7 或更早版本兼容,请将您的项目设置中的部署目标设置为 iOS 8;并且只保留条件的第一部分(删除“else”部分),因为应用程序将始终响应该选择器。对于 iOS 8 的部署目标,编译器会告诉您,如果您到达该行,您将在 iOS 8 设备上执行已弃用的语句。
    • 如果您希望您的应用与 iOS 7 或更早版本兼容,请确保您的项目设置中的部署目标设置为 iOS 7 或更早版本;然后警告应该消失,如果没有,您可以尝试使用此处描述的内容将其静音deprecated warnings in xcode and how to handle deprecation

    【讨论】:

    • 谢谢,它可以工作,但如果我早点选择 IOS 7,它也将与 IOS 8 兼容,不是吗?
    • 如果您选择 iOS7 部署目标,它将适用于 iOS 7 及更高版本(包括 iOS 8)
    猜你喜欢
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    • 1970-01-01
    相关资源
    最近更新 更多