2015-09-13 20 views
6

プッシュ通知のためのParse.comチュートリアルの後、私は自分のアプリケーションのdidFinishLaunchingWithOptionsメソッドにこのスウィフトコードを置く:Parse.com UIRemoteNotificationType非推奨

'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

:私はこれらの2回の警告を取得しています

 // 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) 
    } 

私は単にそれが私に言っているものを交換することはできますか?

答えて

5

答えはかなり白黒です。はい、あなたは1つの警告で簡単に交換することができます:

iOS 7搭載のデバイスをターゲットにしている場合、その必要はありません。しかし、あなたがiOS7のために開発しているなら...私の意見は、それをやめてください。 8月31日とAccording to Appleの時点で、このOSをまだデバイスに搭載しているユーザーはあまり多くなく、そのデータには公開されているiOS 9も含まれていないため、誰も使用していないOSで多くの時間を無駄にしています。しかし、の場合、実際ににiOS 7をサポートする必要がある場合は、非推奨バージョンに加えてすべてを含める必要があります。それ以外の場合は、廃止予定でないバージョンで述べたとおりにスワップアウトできます。返信用

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) 
} 
+0

ありがとう:ここ

スイフト2.0例です。私はiOS 7をターゲットにする必要はありません。そこで、最後の数行を次のように置き換えました。else { let types = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound application.registerForRemoteNotifications(types) } 'エラーが発生しました:タイプUIUserNotificationTypeの引数リストでregisterForRemoteNotificationsを呼び出せません – jordangrogan

+0

私はそれを取得しません。 'registerForRemoteNotifications()'を実行しているあなたのiOS8バージョンでは、どのタイプも渡していません。どのようなタイプの登録が必要かをどのように知っていますか? – Honey