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