我的应用使用GCM接收推送通知.我的Android应用程序完美的工作,当我完全关闭应用程序,我仍然收到通知,但如果我对我的iOS版本做同样的事情,我没有收到任何东西.
请注意,这当然是在应用程序首次注册然后应用程序关闭之后.我找不到很多关于此的信息.有些帖子说你不能这样做.但Facebook和Facebook的使者都喜欢这样做.有谁知道这是怎么做的?
这是我的
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' ) );
请注意,如果应用程序位于后台,则此方法有效
我设法通过将此添加到我的工资负荷来实现这一点
"priority" => "high"
也许有人可以评论为什么这有效,因为我不知道