ios - Parse.com UIRemoteNotificationType 已弃用

标签 ios parse-platform

按照 Parse.com 的推送通知教程,我将此 Swift 代码放入我的应用程序 didFinishLaunchingWithOptions 方法中:

        // Register for Push Notitications
    if application.applicationState != UIApplicationState.Background {
        // Track an app open here if we launch with a push, unless
        // "content_available" was used to trigger a background push (introduced in iOS 7).
        // In that case, we skip tracking here to avoid double counting the app-open.
        
        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)
    }

我收到这两个警告:

'UIRemoteNotificationType' was deprecated in iOS version 8.0: Use UIUserNotificationType for user notifications and registerForRemoteNotifications for receiving remote notifications instead.

'registerForRemoteNotificationsTypes' was deprecated in iOS version 8.0: Please use registerForRemoteNotifications and registerUserNotificationSettings: instead

我能否简单地换掉它告诉我的内容?

最佳答案

答案是非黑即白的。是的,你可以简单地换掉它,但有一个警告:

如果您的目标设备是 iOS 7,则不需要。但是,如果你正在为 iOS7 开发......我的意见是,停止它。截至 8 月 31 日和 According to Apple没有那么多用户在他们的设备上仍然使用这个操作系统,而且这些数据甚至不包括公开的 iOS 9s,所以你在一个没有人使用的操作系统上浪费了很多时间。但是,如果您真的必须支持 iOS 7,那么除了未弃用的版本之外,您还需要包括所有这些。否则,您可以按照未弃用版本的说明将其换掉。

这是一个 Swift 2.0 示例:

if #available(iOS 8.0, *) {
   let types: UIUserNotificationType = [.Alert, .Badge, .Sound]
   let settings = UIUserNotificationSettings(forTypes: types, categories: nil)
   application.registerUserNotificationSettings(settings)
   application.registerForRemoteNotifications()
} else {
   let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
   application.registerForRemoteNotificationTypes(types)
}

关于ios - Parse.com UIRemoteNotificationType 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32545248/

相关文章:

ios - 解析中没有注册设备(推送通知)

ios - 每次笔划更改用户文本字段输入并获取更改的消息

ios - 不同的单元格背景颜色取决于 iOS 版本(4.0 到 5.0)

ios - 无法理解这个返回语句

ios - 更改应用程序中解析推送通知的当前 channel

ios - BOOL 方法的问题

ios - 出列可重用 UITableViewCell 时属性字符串字体格式更改

iphone - iOS:如何使UIImage模糊?

parse-platform - 如何使用子类查询关系数据? parse.com 和 Unity

iphone - 如何获取给定 PFUser 的 facebook 用户名?