无法接收Firebase推送通知

时间:2018-07-18 13:50:12

标签: java ios firebase push-notification firebase-cloud-messaging

我正在使用JAVA admin SDK发送推送通知。我有两个客户端(Android和iOS)。尝试将推送通知发送到FCM ID。能够在android客户端接收通知。但未收到iOS客户端。

当我通过Firebase控制台发送通知时,能够在两个客户端中接收推送通知。

这是用于在iOS客户端中接收推送通知的代码

  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()
    Messaging.messaging().delegate = self
    Messaging.messaging().isAutoInitEnabled = true

              // Receive displayed notifications for iOS 10 devices.
       func userNotificationCenter(_ center: UNUserNotificationCenter,
                            willPresent notification: UNNotification,
                            withCompletionHandler completionHandler: 
          @escaping (UNNotificationPresentationOptions) -> Void) {
    let userInfo = notification.request.content.userInfo
    // Print full message.
    print(userInfo)
    // Change this to your preferred presentation option
    completionHandler([])
}

func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    print(userInfo)
    completionHandler()
}

0 个答案:

没有答案