【发布时间】:2015-12-07 09:13:10
【问题描述】:
我的应用使用 GCM 接收推送通知。我的 android 应用程序完美运行,当我完全关闭应用程序时,我仍然会收到通知,但是如果我对我的 iOS 版本做同样的事情,我什么也不会收到。
请注意,这当然是在应用首次注册然后关闭应用之后。我找不到太多关于这个的信息。有些帖子说你不能这样做。但 facebook 和 facebook messenger 之类的都这样做。有谁知道这是怎么做到的?
这是我的
DidReceiveRemoteNotification method which is taken from the GCM documentation
// [START ack_message_reception]
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Notification received: %@", userInfo);
// This works only if the app started the GCM service
[[GCMService sharedInstance] appDidReceiveMessage:userInfo];
// Handle the received message
// [START_EXCLUDE]
[[NSNotificationCenter defaultCenter] postNotificationName:_messageKey
object:nil
userInfo:userInfo];
// [END_EXCLUDE]
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler
{
NSLog(@"Notification received: %@", userInfo);
// This works only if the app started the GCM service
[[GCMService sharedInstance] appDidReceiveMessage:userInfo];
// Handle the received message
// Invoke the completion handler passing the appropriate UIBackgroundFetchResult value
// [START_EXCLUDE]
[[NSNotificationCenter defaultCenter] postNotificationName:_messageKey
object:nil
userInfo:userInfo];
handler(UIBackgroundFetchResultNoData);
// [END_EXCLUDE]
}
// [END ack_message_reception]
我发送的有效载荷如下所示
$payload = array('registration_ids' => $Regids,
'content_available' => false,
'notification' => array("body"=> $_POST['message'],
"sound" => "default",
'badge' => '1'
)
);
请注意,如果应用程序在后台,则此方法有效
【问题讨论】:
-
请评论否决票,这是一个有效的问题
-
我不是反对票....但我认为您被反对票是因为您没有提供有关您当前正在做什么的任何详细信息(即代码和推送内容) ,以及 iOS 版本)。
-
公平点 :-) 我添加了更多信息
-
太好了 - 现在足够详细,我可以对您的问题以及相关答案进行投票。
标签: ios push-notification google-cloud-messaging