【发布时间】:2018-05-11 09:35:04
【问题描述】:
我正在使用 firebase 进行推送通知。并且我的“didReceiveRemoteNotification”函数没有被调用。我不知道为什么我的函数没有被调用,并且在控制台中也没有收到有效负载数据。请解决我的问题。提前致谢。
**Here is my code:**
FirebaseApp.configure()
Messaging.messaging().shouldEstablishDirectChannel = true
// [START register_for_notifications]
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound],
categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
// [END register_for_notifications]
// Add observer for InstanceID token refresh callback.
NotificationCenter.default
.addObserver(self, selector:
#selector(AppDelegate.tokenRefreshNotification),
name: NSNotification.Name.InstanceIDTokenRefresh,
object: nil)
@objc func tokenRefreshNotification(_ notification: UIViewController)
{
Messaging.messaging().subscribe(toTopic: "Testing")
}
func application(_ application: UIApplication, didReceiveRemoteNotification
userInfo: [AnyHashable : Any])
{
print("userInfo\(userInfo)")
}
【问题讨论】:
-
你看到这个链接了吗? stackoverflow.com/questions/40280986/…
-
这不起作用。请提供有关控制台中未接收有效负载数据的原因的其他信息。 #Manish Mahajan
-
@SanpreetSingh 你在模拟器上测试吗?
-
没有在真机上测试。 #Khushbhu
标签: ios swift firebase push-notification firebase-cloud-messaging