我注意到在iOS 11 beta 2上,application:didReceiveRemoteNotification:fetchCompletionHandler无论应用程序的状态如何(背景/前景),都不会传递静默通知.
我实现了该UIApplicationDelegete方法,application:didReceiveRemoteNotification:fetchCompletionHandler并发送以下静默推送
{
"aps": {
"content-available": 1
},
"mydata": {
"foo": "bar"
}
}
Run Code Online (Sandbox Code Playgroud)
但是在iOS 11上没有调用委托方法.
它在其他版本的iOS上工作正常,文档部分配置静默通知没有提到应该做的任何其他事情.
这是iOS 11中的错误还是我错过了iOS 11中的新功能?
请注意,我不是在讨论或使用UserNotification发送静默推送所不需要的框架.
这是一个说明问题的示例项目(您必须设置自己的包ID)
当您在示例项目中进行午餐并将上述有效负载发送到应用程序时,您可以使用macOS控制台查看推送是否已正确传递到设备,而不是应用程序.
看来行为是随机的.有时在重新启动设备后,有效负载会正确传送,但一段时间后它会停止工作.
正如您在下面的屏幕截图中看到的那样,标记为1的推送仅对设备进行了延迟,并且推送2(设备重启后)也会传送到应用程序.
还是一样的行为.应该起作用的另一件事但不是以下.当应用程序的方案设置为"等待可执行文件启动"时,静音推送应该唤醒应用程序并在后台启动它.
在错误报告中仍然是Apple的相同行为而不是更新.
仍然是同样的问题.我现在使用的重现步骤如下:
didReceiveRemoteNotification: fetchCompletionHandler预期:应用程序从暂停状态进入后台并被didReceiveRemoteNotification: fetchCompletionHandler调用
实际:没有任何反应
push-notification apple-push-notifications ios remote-notifications silent-notification
我在iOS上遇到FCM通知问题.
我收到成功通知时,我的应用程序是在前台(回调didReceiveRemoteNotification中appdelegate被解雇),但是当应用程序在后台我没有收到通知(我看不出在iOS中的通知栏,任何东西).
所以,我认为问题在于FCM发送的消息格式.我的服务器发送给FCM的json采用以下格式:
{
"data":{
"title":"mytitle",
"body":"mybody",
"url":"myurl"
},
"notification":{
"title":"mytitle",
"body":"mybody"
},
"to":"/topics/topic"
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我的json中有两个块:一个通知块(用于接收后台通知)和一个数据块(用于接收前台通知).
我无法理解为什么没有收到后台通知.我的疑问是关于块的顺序(如果我在"通知"块之前放置"数据"块会有问题吗?).
编辑: 有关该问题的更多信息.
这是我的appdelegate.swift:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?
// Application started
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool
{
let pushNotificationSettings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(pushNotificationSettings)
application.registerForRemoteNotifications()
FIRApp.configure()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "tokenRefreshNotification:", name: kFIRInstanceIDTokenRefreshNotification, object: nil)
return true
}
// Handle refresh notification token
func tokenRefreshNotification(notification: NSNotification) {
let …Run Code Online (Sandbox Code Playgroud) ios firebase google-cloud-messaging swift firebase-cloud-messaging