푸시 알림을 통합하려는 게임을 만들고 있습니다. 사용 편의성을 위해 FCM에 연결하여 Google의 서비스를 신뢰했습니다.Cocos2d FCM 푸시 알림이 작동하지 않습니다.
필자는 FCM을 적절히 통합했지만, 무엇이 빠졌는지 여전히 알 수는 없지만 Firebase 콘솔에서 알림을 보내면 내 장치에서 알림을받을 수 없습니다.
처음부터 알림을 수신 할 수 있었지만 알림도 수신 할 수있었습니다. 알림도 무시할 수 있지만 이후에는 동일한 코드 및 개발 프로필로 알림 이벤트를 수신 할 수 없습니다.
누군가 내 실수를 지적하고로드 블록을 정리하는 데 도움이 될 수 있습니다. 내가적인 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.")
}
에 내 코드를 작성했습니다 얻기 다음 장치 토큰 :
cMqaF0FVwbY : APA91bFMzsUmP2NKSipGMC7NTehPjBDWE72S6Fdi13iVV51ziPZvVkVw3g5NXEGooII5IVwby3ekBS4MquWyRQyF7rXDnWTDvY6eDPtL_kQQDk3Wen6V0DPv2Yf-Ym6YPi8k66aW6I-O
기기 토큰도 얻을 수 있습니다. 알림을받을 수 없습니다.
당신은 더 이상 설명이 필요하면 알려 주시기 바랍니다.
내 코드를 참조하십시오? –
@ArthurThompson 예 했어요. setupPushNotification 함수에서 코드를 확인할 수 있습니다. –
먼저이 메소드를 호출하기 전에 Device Token을 가져 오는 지 확인하십시오. connectToFcm()? –