xcode Firebase 推送通知在 iOS 13 上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/58198340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Firebase Push notifications don't work on iOS 13
提问by pajtimid
Firebase push notifications aren't working on iOS 13. But works fine in iOS 12.4. Any solution?
Firebase 推送通知不适用于 iOS 13。但在 iOS 12.4 中工作正常。有什么解决办法吗?
Edited: 04.10.19
编辑:04.10.19
Silent push notification not working iOS 13
静默推送通知不起作用 iOS 13
采纳答案by HyunGyu Hwang
Example Firebase push body
Firebase 推送主体示例
{
"topic": "topic_test",
"message": {
"data": {
"key": "some_value"
},
"notification": {
"body": "description ~",
"title": "title !"
}
},
"options": {
"mutableContent": true,
"contentAvailable": true,
"apnsPushType": "background"
}
}
回答by Sandip Patel - SM
Quick Fix Solution:
快速修复解决方案:
If you are facing issue to receive push notification on iOS version 13.2.X, then do below change in device settings and check again:
如果您在 iOS 版本 13.2.X 上遇到接收推送通知的问题,请在设备设置中进行以下更改并再次检查:
Device > Settings > Search your AppName > Notifications > Banner Style >Change it to "Persistent" from "Temporary"or vise-versa one time.
设备 > 设置 > 搜索您的 AppName > 通知 >横幅样式 > 将其从“临时”更改为“持久”,反之亦然。
Now send push notification again and its start receiving.
现在再次发送推送通知并开始接收。
回答by Amal T S
If the delegate didRegisterForRemoteNotificationsWithDeviceToken
triggering failed, try changing the network. I changed it to cellular data & it started working again
如果委托didRegisterForRemoteNotificationsWithDeviceToken
触发失败,请尝试更改网络。我将其更改为蜂窝数据并再次开始工作
Also, if you used your internet connection in the MAC to share using USB. Turn it off & connect your IPhone with a normal wifi or mobile data.
此外,如果您在 MAC 中使用 Internet 连接来使用 USB 进行共享。将其关闭并使用普通 wifi 或移动数据连接您的 iPhone。
回答by Nikhil Jobanputra
Hope you add Notification delegate and other method
希望您添加通知委托和其他方法
So first can you try with postman using this below link
所以首先你可以使用下面的链接与邮递员一起尝试
https://fcm.googleapis.com/fcm/send
https://fcm.googleapis.com/fcm/send
In postman header 1). Authorization = key="Add Firebase server key" 2). Content-Type = application/json
在邮递员标题 1) 中。授权 = key="添加 Firebase 服务器密钥" 2). 内容类型 = 应用程序/json
In postman body as row
在邮递员身上作为行
{ "to" : "Your iPhone Device FCM Toen", "notification" : { "body" : "Body of Your Notification", "title": "Title of Your Notification", "sound": "default", "alert":"New" }, "priority": "high", "contentAvailable": true, "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", } }
{ "to" : " Your iPhone Device FCM Toen", "notification" : { "body" : "Body of Your Notification", "title": "你的通知标题", "sound": "default", "alert" ":"New" }, "priority": "high", "contentAvailable": true, "data" : { "body": "Body of Your Notification in Data", "title": "Title of Your Notification in Title ", "key_1" : "key_1 的值", "key_2": "key_2 的值", } }
First try using postman with above example and check in iOS 13
首先尝试在上面的例子中使用邮递员并检查 iOS 13
回答by Gautam Mistry
Maybe its pattern of iOS13 bug or updates, This will be work for iOS12 & iOS13
也许它的 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"
}
}
回答by eliamyro
Prior to iOS 13 I had an issue of not receiving push notifications because I didn't select in XCode - Signing and Capabilities -> Background Modes -> Background Fetch. After I selected it everything worked fine. After iOS 13 I have the same issue of not receiving push notifications anymore. Today I saw that in XCode the Background Fetch option was unselected again. Maybe something happened after the update of the XCode??
在 iOS 13 之前,我遇到了无法接收推送通知的问题,因为我没有在 XCode 中选择 - 签名和功能 -> 后台模式 -> 后台获取。我选择它后一切正常。在 iOS 13 之后,我遇到了不再接收推送通知的相同问题。今天我看到在 XCode 中,Background Fetch 选项再次被取消选中。也许在 XCode 更新后发生了一些事情?
I haven't test it yet. Check if this is a solution for you.
我还没有测试它。检查这是否适合您。
回答by Mr.P
Could be to do with the way the push token gets pulled out of the Data
object. I'm not super familiar with Firebase push notifications, but if you have to pass the push token to Firebase, you may need to change the way you get the token. If Firebase has an SDK that handles this, you may need to update it.
可能与推送令牌从Data
对象中拉出的方式有关。我对 Firebase 推送通知不是很熟悉,但是如果您必须将推送令牌传递给 Firebase,您可能需要更改获取令牌的方式。如果 Firebase 有处理此问题的 SDK,您可能需要更新它。
OneSignal talk about the change here.
OneSignal 在这里谈谈变化。
回答by Chazz
I had the same issue after updating my Pods. As of Version 6.18.0:
更新 Pod 后,我遇到了同样的问题。从 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.
弃用了通过 shouldEstablishDirectChannel 的 FCM 直接通道消息传递。相反,使用 APNs 进行下游消息传递。如果您想继续使用旧 API,请将 content_available 密钥添加到您的负载,但我们强烈建议使用 HTTP v1 API,因为它提供完整的 APNs 支持。已弃用的 API 将在 Firebase 7 (#4710) 中删除。”发行说明。
In my AppDelegate I commented out 2 lines of code:
在我的 AppDelegate 中,我注释掉了 2 行代码:
func connectToFCM() {
// Messaging.messaging().shouldEstablishDirectChannel = true
}
func disconnectFCM() {
// Messaging.messaging().shouldEstablishDirectChannel = false
}
Everything seemed to be working when I would send a notification to my device using it's device token. However, after uploading my update to the App Store I was seeing
当我使用它的设备令牌向我的设备发送通知时,一切似乎都在工作。但是,在将我的更新上传到 App Store 后,我看到
0% of potential users are eligible for this campaign: 0
0% 的潜在用户有资格参加此活动:0
I re-downloaded the GoogleService-Info.plist from Firebase and compared it to what was already in my xcworkspace. The GOOGLE_APP_ID had changed. So, replacing the .plist fixed it. I'm not sure why the info in the .plist would change. Hope this helps.
我从 Firebase 重新下载了 GoogleService-Info.plist,并将其与我的 xcworkspace 中已有的内容进行了比较。GOOGLE_APP_ID 已更改。因此,替换 .plist 修复了它。我不确定为什么 .plist 中的信息会改变。希望这可以帮助。
ps- current Pods are 6.23.0
ps- 当前 Pod 是 6.23.0