按照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)
}
我收到以下两个警告:我可以简单地换掉告诉我的内容吗?
最佳答案
答案是非常黑白的。是的,您可以简单地将其替换掉,只需提出以下警告:
如果要使用iOS 7定位设备,则不需要。但是,如果您正在为iOS7开发...我认为,请停止它。截至8月31日和According to Apple,没有多少用户仍在其设备上使用此操作系统,并且该数据甚至不包括公共(public)iOS 9s,因此您在没有人使用的OS上浪费了大量时间。但是,如果您确实必须支持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/