繼Parse.com教程推送通知,我把這個斯威夫特代碼到我的應用程序didFinishLaunchingWithOptions方法:Parse.com UIRemoteNotificationType已過時
// 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,所以我用最後幾行代碼替換了:'} else {type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound application.registerForRemoteNotifications(types) }'但我得到錯誤:無法用類型爲UIUserNotificationType的參數列表調用registerForRemoteNotifications – jordangrogan
我不明白。對於你正在做的iOS8版本:'registerForRemoteNotifications()',但你沒有傳遞任何類型。它如何知道它必須註冊哪些類型? – Honey