我已经在我的应用程序中添加了远程通知功能,我可以接收推送通知,但是当我收到它时,没有显示自动弹出窗口。
这是我的AppDelegate代码:
func application( application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print("Notification received: \(userInfo)")
GCMService.sharedInstance().appDidReceiveMessage(userInfo);
// Handle the received message
NSNotificationCenter.defaultCenter().postNotificationName(messageKey, object: nil,userInfo: userInfo)
我的应用已正确连接到GCM服务器,并在收到通知时收到以下日志:
Notification received: [collapse_key: do_not_collapse, from: 22334444232]
在服务器端,我发送基本的有效负载,例如:
{{"aps":{"alert":"Hello world!","badge":0, "sound": "default"}, "to":"MY_TOKEN_KEY", }
任何想法为什么我的应用程序没有自动处理收到的通知?
EDIT1:
我还尝试更改消息有效负载以匹配Google的IOS GCM教程:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "Hello world",
"title" : "alert data"
}
}
但仍然只是使用以下日志调用didReceiveRemoteNotification函数:
Notification received : [aps: {
alert = {
body = "Hello world";
title = "alert data";
};
},gcm.message_id:0:1470516999022408%f1xxxxxx ....]