我在 iOS7 中实现了推送通知。由于iOS7具有通过使用方法静默接收推送通知的特性
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo performFetchWithCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler
{
}
但是在我发送通知时此方法从未被调用。我在通知托盘中收到通知但是通知不应该在那里,因为它是无声的。我正在使用 Raywenderlich 的 PHP 代码发送推送通知。我也像这样添加了内容可用 key
// Create the payload body
$body['aps'] = array(
'content-available' => '1',
'alert' => $message,
'sound' => 'default'
);
请帮忙!!!
最佳答案
如果你想静默推送通知,你不应该在你的有效负载中添加'alert'参数。
像这样传递你的参数。
$body['aps'] = array(
'content-available' => '1'
);
并验证您在项目 plist 中启用了远程通知。
或
您将通过实现此委托(delegate)获得通知。
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
// Call or write any code necessary to download new data.
completionHandler(UIBackgroundFetchResultNewData);
}
关于iOS7 静默推送通知不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20798516/