Firebase Messaging在收到推送通知时不会唤醒iOS设备

时间:2018-03-26 19:11:58

标签: ios firebase apple-push-notifications firebase-cloud-messaging

我正在使用FCM将推送通知发送到单个iOS设备,这是通过对Firebase云功能的http请求触发的。在关注FCM和APNs文档后,当应用程序在后台运行时,一切正常。我在所有情况下都成功收到了通知。

唯一的问题:推送通知未点亮我的锁定屏幕。 我仍然收到推送通知,当我按下主页按钮手动唤醒设备时可以看到它。但通知本身不会唤醒我的设备。

如何复制

  1. 打开应用
  2. 按主页按钮(现在应用程序现在处于后台)
  3. 锁定手机
  4. 发送推送通知
  5. 收到Notif但没有点亮锁定屏幕。
  6. 我已经开启了背景模式'能力>选择了“远程通知”和“#39;和'背景提取'我的部署目标是10.0。我的应用程序允许锁屏通知。

    (类似问题的大多数答案都是,"打开背景模式"或者"将内容设置为1,"我已经完成了两者。)

    我的云功能将有效负载发送到APN:

    exports.pushMatchNotif = functions.https.onRequest((req, res) => {
      let receiverToken = req.receiverToken
    
      var msg = {
      'apns': {
        'header': {
          'apns-priority': '10'
        },
        'payload': {
          'aps': {
            'alert': {
              'title': 'Hi',
              'body': 'Hello',
            },
            'badge': 2,
            'sound': 'default'
            'content-available': 1
          }
        }
      },
      'token': receiverToken
    };
    
    
      admin.messaging().send(msg)
      .then((response) => {
        // Response is a message ID string.
        console.log('Successfully sent message:', response);
        let json = {"Response": response}
        res.send(json)
      })
      .catch((error) => {
        console.log('Error sending message:', error);
        let json = {"Error": error}
        res.send(json)
      });
    
    })
    

    我的didFinishLaunchingWithOptions方法:

        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
        FirebaseApp.configure()
    
        Messaging.messaging().delegate = self
        UNUserNotificationCenter.current().delegate = self
    
        let center = UNUserNotificationCenter.current()
        center.requestAuthorization(options: [.alert, .badge , .sound]) {
            (granted, error) in
            print("granted is \(granted)")
        }
        application.registerForRemoteNotifications()
    
        return true
    }
    

    我的didReceiveRegistrationToken方法(FCM委托方法):

     func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
    
            print("Firebase deviced token: \(fcmToken)")
    
        }
    

    我的didReceiveRemoteNotification方法:

        func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
        }
    
        // Print full message.
        print(userInfo)
    
    }
    

    我缺少什么?

1 个答案:

答案 0 :(得分:0)

我有同样的问题。原来我启用了“请勿打扰”模式。禁用固定修复即可解决。