プッシュ通知を統合したいゲームを作成しています。私はFCMに接続して、Googleのサービスを信頼して使いやすくしました。Cocos2d FCMプッシュ通知が機能しない
FCMは正しく統合されていますが、何が欠けているのかは分かりませんが、Firebaseコンソールから通知を送信すると、デバイス上で通知が受信されません。
私は無知で失われた通知を受け取ることができましたが、その後は同じコードと開発プロファイルで通知イベントを受け取ることができません。
誰かが私の間違いを指摘して、私がロードブロッキングをクリアするのを助けてくれれば幸いです。
私はCocos2dゲームでFCMを統合していますように、私は次のデバイストークンを取得MainScene.swiftcMqaF0FVwbY:APA91bFMzsUmP2NKSipGMC7NTehPjBDWE72S6Fdi13iVV51ziPZvVkVw3g5NXEGooII5IVwby3ekBS4MquWyRQyF7rXDnWTDvY6eDPtL_kQQDk3Wen6V0DPv2Yf-Ym6YPi8k66aW6I-O
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.")
}
に私のコードを書かれている
デバイストークンも取得できますが、通知を受け取ることができません。
さらに詳しい説明が必要な場合はお知らせください。
あなたがregisterForRemoteNotificationsを呼んだここに私のコードを参照してください? –
@ArthurThompsonはいそうでした。 setupPushNotification関数でコードをチェックすることができます。 –
まず、このメソッドを呼び出す前にデバイストークンが取得されていることを確認しますconnectToFcm()? –