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

3

我正在尝试设置我的应用程序以从GCM接收推送通知。当应用程序在前台运行时,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 为什么我的应用程序在后台运行时没有通知横幅?

当您的应用程序处于后台时,didFinishLaunchingWithOptions方法会被调用,您可以在其中展示您的代码... 您解决了这个问题吗? - XcodeNOOB
1个回答

0

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

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

警告:JSON 可能有误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接