sri*_*low 1 push-notification ios firebase swift firebase-cloud-messaging
您好,FCM在我的应用程序中使用。
当我尝试读取FCM令牌时,即使编译器不调用此委托方法也是任何方式请帮助。
当我休息并检查此方法时,请不要调用我使用 ios11 swift4
extension AppDelegate: MessagingDelegate{
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
let dataDict:[String: String] = ["token": fcmToken]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Message data:", remoteMessage.appData)
}
}
Run Code Online (Sandbox Code Playgroud)
didReceiveRegistrationToken
Run Code Online (Sandbox Code Playgroud)
是一个委托函数。它会在收到来自 firebase 的令牌时被调用。如果它没有被调用,请确保您在 AppDelegate 中遵循了代码
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
return true
}
Run Code Online (Sandbox Code Playgroud)
与 Messaging.messaging().delegate = self我们正在注册AppDelegate用于接收从火力地堡方法调用