jor*_*gan 6 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)
}
Run Code Online (Sandbox Code Playgroud)
我收到这两个警告:
iOS版本8.0中不推荐使用"UIRemoteNotificationType":使用UIUserNotificationType进行用户通知,使用registerForRemoteNotifications接收远程通知.
iOS版本8.0中不推荐使用'registerForRemoteNotificationsTypes':请使用registerForRemoteNotifications和registerUserNotificationSettings:
我可以简单地换掉它告诉我的东西吗?
答案非常黑白分明.是的,您可以简单地将其换掉,但需要注意一点:
如果您的目标设备是iOS 7,那么您就不需要了.但是,如果您正在开发iOS7 ...我的意见,请停止它.截至8月31日,据Apple称,没有那么多用户在他们的设备上仍然拥有这个操作系统,而且数据甚至不包括公共iOS 9,所以你在操作系统上浪费了很多时间没人使用.但是,如果您真的必须支持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)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2213 次 |
| 最近记录: |