2016-11-17 28 views
0

私はXcodeの8に私のXcodeを更新しているので:プッシュ通知に登録するにはどうすればいいですか?

  • 有効プッシュ通知機能で資格:

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { 
        // 
    } 
    

    が呼び出されることはありません、私はすべてを試してみました。

  • インポートされたユーザー通知が追加され、UIApplicationDelegate,UNUserNotificationCenterDelegateが追加されました。 applicationDidFinishLaunchingから
  • 追加この:

    if #available(iOS 10.0, *){ 
        UNUserNotificationCenter.current().delegate = self 
    
        UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert], completionHandler: {(granted, error) in 
         if (granted) 
         { 
    
          UIApplication.shared.registerForRemoteNotifications() 
    
    
         } 
         else{ 
          //Do stuff if unsuccessful... 
         } 
        }) 
    

それでもdidRegisterForRemoteNotificationsWithDeviceToken関数が呼び出されることはありません! 助けてください。

はまた、私はこの警告を受けています注意:私はXcodeのコードをマーキングして言い続け、同様の問題に遭遇した

Instance method application(:didRegisterForRemoteNotificationsWithDeviceTok‌​en:) nearly matches optional requirement application(:didRegisterForRemoteNotificationsWithDeviceTok‌​en:) of protocol UIApplicationDelegate

+0

'didRegisterForRemote ...'メソッド全体をコメント化し、コード補完を使用するために再入力しようとしましたか? – vadian

+0

はい私もしなかった –

答えて

0

を:「ほぼオプションの要件に合致する」 これはバグであると報告されていますレーダーバグレポートが提出されているそれは私に同じ警告を与え、アプリがと言ってクラッシュ保管場所私は

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) 

と同じ問題に遭遇した「委任がlocationManagerに応答する必要があります:didFailWithError:」私のために働いた

ソリューション:

@objc(locationManager:didFailWithError:) 
    func locationManager(_ manager: CLLocationManager, didFailWithError error: NSError) { 
     print(error) 
} 
+0

うまくいけば、これは誰かに役立つだろう..私は私の以前の応答を編集し、私のために働いたソリューションを追加しました。 NSError(objcコード形式を使用しているため、エラーではありません)を使用する必要があります。 – user3349763

関連する問題