简体   繁体   English

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

[英]Push Notification is not showing when app is in background

I'm trying to setup my application to receive push notification from GCM. 我正在尝试设置我的应用程序以接收来自GCM的推送通知。 When app is running in foreground the method in AppDelegate is calling: 当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);
}

The example log is like that: 示例日志是这样的:

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

The problem is that when my application is in the background there is no information at all in notification center, no alert/banner is showing. 问题是当我的应用程序在后台时,通知中心根本没有信息,没有显示警报/横幅。 I checked in settings->notifications and notifications are enabled for my app. 我检查了设置 - >通知,并为我的应用启用了通知。 When I enter to my app that was in the background then I have information about notification but this is not what I want. 当我进入后台的应用程序时,我有关于通知的信息,但这不是我想要的。

I'm using iOS 9.0.1 with xCode 7.1 Why there is no notification banner when my app is in background? 我正在使用带有xCode 7.1的iOS 9.0.1为什么当我的应用程序处于后台时没有通知横幅?

Compare your payload with example from Apple site 比较您的有效负载与Apple站点的示例

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

Alert json is probably wrong. 警报json可能是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM