Firebase 推送通知不适用于 iOS 13

Firebase Push notifications don't work on iOS 13

Firebase 推送通知在 iOS 13 上不起作用。但在 iOS 12.4 上工作正常。有什么解决办法吗?

编辑:2019 年 10 月 4 日

静默推送通知不起作用iOS 13

可能与推送令牌从 Data 对象中拉出的方式有关。我不是很熟悉 Firebase 推送通知,但是如果您必须将推送令牌传递给 Firebase,您可能需要更改获取令牌的方式。如果 Firebase 有处理此问题的 SDK,您可能需要更新它。

OneSignal 谈谈变化here

Ref link here

Firebase 推送正文示例

{
  "topic": "topic_test",
  "message": {
    "data": {
      "key": "some_value"
    },
    "notification": {
      "body": "description ~",
      "title": "title !"
    }
  },
  "options": {
    "mutableContent": true,
    "contentAvailable": true,
    "apnsPushType": "background"
  }
}

在 iOS 13 之前,我遇到了无法接收推送通知的问题,因为我在 XCode 中没有 select - 签名和功能 -> 后台模式 -> 后台获取.在我 select 编辑它之后一切正常。 在 iOS 13 之后,我遇到了同样的问题,即不再收到推送通知。今天我看到 XCode 中的 Background Fetch 选项再次被取消select。也许 XCode 更新后发生了什么??

我还没有测试过。检查这是否适合您。

如果代理didRegisterForRemoteNotificationsWithDeviceToken触发失败,请尝试更换网络。我将其更改为蜂窝数据并再次开始工作

此外,如果您在 MAC 中使用互联网连接来使用 USB 进行共享。将其关闭并使用普通 wifi 或移动数据连接您的 IPhone。

希望你添加通知委托和其他方法

所以首先你可以尝试使用下面的邮递员 link

https://fcm.googleapis.com/fcm/send

在邮递员中header 1).授权=密钥="Add Firebase server key" 2). Content-Type = application/json

在邮递员 body 中作为行

{ "to" : "您的 iPhone 设备 FCM Toen", "notification":{ "body" : "Body of Your Notification", "title": "Title of Your Notification", "sound": "default", "alert":"New" }, "priority": "high", "contentAvailable":是的, "data":{ "body" : "Body of Your Notification in Data", "title": "Title of Your Notification in Title", "key_1" : "Value for key_1", "key_2" : "Value for key_2", } }

首先尝试在上面的示例中使用邮递员并签入 iOS 13

可能是 iOS13 错误或更新的模式, 这将适用于 iOS12 & iOS13

{
"to":"",
"priority":"high",
"content_available":true,
"data":{
    "abc":"abc"
    },
"notification":{
    "body":"abc"
    }
}

Or

{
"to":"",
"priority":"high",
"content_available":true,
"data":{
    "abc":"abc"
    }
}

快速修复解决方案:

如果您在 iOS 版本 13.2.X 上接收推送通知时遇到问题,请在设备设置中执行以下更改并再次检查:

设备 > 设置 > 搜索您的 AppName > 通知 > 横幅样式 > 将其从 "Temporary"[=24 更改为 "Persistent" =] 或反之亦然一次。

现在再次发送推送通知并开始接收。

更新 Pods 后我遇到了同样的问题。从版本 6.18.0 开始:

Deprecated FCM direct channel messaging via shouldEstablishDirectChannel. Instead, use APNs for downstream message delivery. Add content_available key to your payload if you want to continue use legacy APIs, but we strongly recommend HTTP v1 API as it provides full APNs support. The deprecated API will be removed in Firebase 7 (#4710)." Release notes.

在我的 AppDelegate 中,我注释掉了 2 行代码:

func connectToFCM() {
//        Messaging.messaging().shouldEstablishDirectChannel = true
    }

func disconnectFCM() {
//        Messaging.messaging().shouldEstablishDirectChannel = false
    }

当我使用设备令牌向我的设备发送通知时,一切似乎都正常。但是,将我的更新上传到 App Store 后,我看到

0% of potential users are eligible for this campaign: 0

我从 Firebase 重新下载了 GoogleService-Info.plist 并将其与我的 xcworkspace 中已有的进行比较。 GOOGLE_APP_ID 已更改。因此,替换 .plist 修复了它。我不确定为什么 .plist 中的信息会改变。希望这个帮助ps。

ps- 当前 Pods 是 6.23.0