电容器推送通知回调未被调用
Capacitor PushNotification Callback nor being called
我在我的应用程序上使用推送通知插件,但回调不起作用PushNotifications.addListener( 'registration', ( token: PushNotificationToken ) => ...
有没有人以前经历过这样的事情?
发现问题... AppDelegate.swift
和 Podfile
文件中有一段代码需要更改。
AppDelegate.swift:
改变这个:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: deviceToken)
}
为此:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidFailToRegisterForRemoteNotificationsWithError.name()), object: error)
} else if let result = result {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: result.token)
}
}
}
播客文件:
在capacitor_pods下添加:
pod 'Firebase/Messaging'
我在我的应用程序上使用推送通知插件,但回调不起作用PushNotifications.addListener( 'registration', ( token: PushNotificationToken ) => ...
有没有人以前经历过这样的事情?
发现问题... AppDelegate.swift
和 Podfile
文件中有一段代码需要更改。
AppDelegate.swift: 改变这个:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: deviceToken)
}
为此:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidFailToRegisterForRemoteNotificationsWithError.name()), object: error)
} else if let result = result {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: result.token)
}
}
}
播客文件:
在capacitor_pods下添加:
pod 'Firebase/Messaging'