我在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