0

プッシュ通知を統合したいゲームを作成しています。私はFCMに接続して、Googleのサービスを信頼して使いやすくしました。Cocos2d FCMプッシュ通知が機能しない

FCMは正しく統合されていますが、何が欠けているのかは分かりませんが、Firebaseコンソールから通知を送信すると、デバイス上で通知が受信されません。

私は無知で失われた通知を受け取ることができましたが、その後は同じコードと開発プロファイルで通知イベントを受け取ることができません。

誰かが私の間違いを指摘して、私がロードブロッキングをクリアするのを助けてくれれば幸いです。

cMqaF0FVwbY:APA91bFMzsUmP2NKSipGMC7NTehPjBDWE72S6Fdi13iVV51ziPZvVkVw3g5NXEGooII5IVwby3ekBS4MquWyRQyF7rXDnWTDvY6eDPtL_kQQDk3Wen6V0DPv2Yf-Ym6YPi8k66aW6I-O

私はCocos2dゲームでFCMを統合していますように、私は次のデバイストークンを取得MainScene.swift

override func onEnter() { 
     super.onEnter() 

     //if !self.globalHolders.isFBaseConfigured { 
      self.setupPushNotification()     
     // self.globalHolders.isFBaseConfigured = true 
     //} 

    } 

    override func onExit() { 
     super.onExit() 

     NSNotificationCenter.defaultCenter().removeObserver(self, name: kFIRInstanceIDTokenRefreshNotification, object: nil) 
     NSNotificationCenter.defaultCenter().removeObserver(self, name: UIApplicationDidBecomeActiveNotification, object: nil) 
     NSNotificationCenter.defaultCenter().removeObserver(self, name: UIApplicationDidEnterBackgroundNotification, object: nil) 
    } 


    func setupPushNotification() { 
     let application = UIApplication.sharedApplication() 

     // Register for remote notifications 
     if #available(iOS 8.0, *) { 
      let settings: UIUserNotificationSettings = 
      UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) 
      application.registerUserNotificationSettings(settings) 
      application.registerForRemoteNotifications() 
     } else { 
      // Fallback 
      let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound] 
      application.registerForRemoteNotificationTypes(types) 
     } 

     FIRApp.configure() 

     // Add observer for InstanceID token refresh callback. 
     NSNotificationCenter.defaultCenter().addObserver(self, selector: "tokenRefreshNotification:", 
      name: kFIRInstanceIDTokenRefreshNotification, object: nil) 

     NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive:", name: UIApplicationDidBecomeActiveNotification, object: nil) 
     NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground:", name: UIApplicationDidEnterBackgroundNotification, object: nil) 
    } 

    func tokenRefreshNotification(notification: NSNotification) { 
     let refreshedToken:String? = FIRInstanceID.instanceID().token() 
     print("InstanceID token: \(refreshedToken)") 

     // Connect to FCM since connection may have failed when attempted before having a token. 
     connectToFcm() 
    } 

    func connectToFcm() { 
     FIRMessaging.messaging().connectWithCompletion { (error) in 
      if (error != nil) { 
       print("Unable to connect with FCM. \(error)") 
      } else { 
       print("Connected to FCM.") 
      } 
     } 
    } 

    func didBecomeActive(application:UIApplication) { 
     NSLog("Did Become Active") 
     connectToFcm() 
    } 

    func didEnterBackground(application: UIApplication) { 
     NSLog("Did enter background") 
     FIRMessaging.messaging().disconnect() 
     NSLog("Disconnected from FCM.") 
    } 

に私のコードを書かれている

デバイストークンも取得できますが、通知を受け取ることができません。

さらに詳しい説明が必要な場合はお知らせください。

+1

あなたがregisterForRemoteNotificationsを呼んだここに私のコードを参照してください? –

+0

@ArthurThompsonはいそうでした。 setupPushNotification関数でコードをチェックすることができます。 –

+0

まず、このメソッドを呼び出す前にデバイストークンが取得されていることを確認しますconnectToFcm()? –

答えて

0

トークンを取得するNotification.objectを使用してチェックします。 とFirebase Push Notification

func tokenRefreshNotification(notification: NSNotification) { 
    let refreshedToken:String? = notification.object 
    print("InstanceID token: \(refreshedToken)") 

    // Connect to FCM since connection may have failed when attempted before having a token. 
    connectToFcm() 
} 
+0

My tokenRefreshNotification毎回呼び出されていません。 –

関連する問題