Ios 已收到Swift推送通知,但未弹出

Ios 已收到Swift推送通知,但未弹出,ios,notifications,google-cloud-messaging,Ios,Notifications,Google Cloud Messaging,我已经在我的应用程序中添加了远程通知功能,我可以接收推送通知,但当我收到时,不会显示自动弹出窗口 这里是我的AppDelegate代码: func application( application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { print("Notification received: \(userInfo)")

我已经在我的应用程序中添加了远程通知功能,我可以接收推送通知,但当我收到时,不会显示自动弹出窗口

这里是我的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", }
你知道为什么我的应用程序不会自动处理收到的通知吗

编辑1:

我还尝试更改消息有效负载,以匹配谷歌的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"
}
}

但仍然只是通过以下日志调用DidReceiveEmotentification函数:

Notification received : [aps: {
alert =     {
    body = "Hello world";
    title = "alert data";
};

},gcm.message_id:0:147051699902408%f1xxx…)

收到通知时,您是否正在使用该应用程序?当收到远程通知时,如果应用程序位于前台,ios将不会弹出警报。如果没有,您需要检查GCM通知有效负载格式。是的,应用程序位于前台。但是如果我将应用程序放在后台,GCM连接将被禁用…不,它仍将工作,否则GCM将无效…我认为套接字连接用于其他目的。你可以做一个测试。你是对的…它只在后台工作…当应用程序在前台时不可能弹出notif?可能是通过使用警报消息?当应用程序位于前台时,您可以发送本地通知,以便通知面板将有记录。或者您可以只显示UIAlertView来通知用户?