当应用在后台时,推送通知未显示

时间:2015-11-05 13:38:53

标签: ios push-notification

我尝试设置我的应用程序以接收来自GCM的推送通知。当app在前台运行时,AppDelegate中的方法正在调用:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
DLog(@"Notification received: %@", userInfo);
// This works only if the app started the GCM service
[[GCMService sharedInstance] appDidReceiveMessage:userInfo];

completionHandler(UIBackgroundFetchResultNoData);
}

示例日志就是这样:

Notification received: {
aps =     {
    alert = "myk myk";
    badge = 2;
    sound = default;
    };
"gcm.message_id" = "0:1446730003823773%cc4efdeacc4efdea";
}

问题是,当我的应用程序在后台时,通知中心根本没有任何信息,没有显示警告/横幅。我检查了设置 - >我的应用已启用通知和通知。当我进入我在后台的应用程序时,我有关于通知的信息,但这不是我想要的。

我使用iOS 9.0.1和xCode 7.1 为什么我的应用在后台时没有通知横幅?

1 个答案:

答案 0 :(得分:0)

将您的有效负载与Apple网站上的示例进行比较

{
"aps" : {
    "alert" : {
        "title" : "Game Request",
        "body" : "Bob wants to play poker",
        "action-loc-key" : "PLAY"
    },
    "badge" : 5
},
"acme1" : "bar",
"acme2" : [ "bang",  "whiz" ]
}

警告json可能是错误的。