我可以使用苹果推送通知服务让我的应用程序做一些事情,而不通知iOS 7中的用户

我的algorithm希望以这种方式工作 –

如果在我的服务器上发生了一些所需的事件,那么我希望向我的应用程序(前台或后台)的每个用户发送less量数据。 但是,而不是通知用户,我希望我的应用程序做一些数据计算和确认服务器。 切记不要通知用户。

您可以使用推送通知数据和application:didReceiveRemoteNotification:fetchCompletionHandler:content-available密钥application:didReceiveRemoteNotification:fetchCompletionHandler: 对于你的用例来说,这可能被认为是一个黑客攻击,如果你尝试使用它,你会受到苹果系统的限制。

您可以在iOS 7上执行此操作。请参阅iOS应用程序编程指南中的 “定期获取less量内容”一节。

您可以发送“空”推送通知(无文字,无声音,无图标)。 这种通知是允许的,可用于与服务器同步(以避免从应用程序端的昂贵的重复轮询)。

如果你的应用程序没有运行,那么在跳板通知中不会显示这样的通知。

如果它正在运行,那么它会收到通知 – 你只需要确保你不显示空的(如果你也使用实际内容的通知)。 你的iOS代码看起来有点像:

 - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { NSString *message = nil; id alert = [userInfo objectForKey:@"aps"]; if ([alert isKindOfClass:[NSString class]]) { message = alert; } else if ([alert isKindOfClass:[NSDictionary class]]) { message = [alert objectForKey:@"alert"]; } if (message) { if (![message isEqualToString:@""]) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"notification" message: message delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } } else { //this was an empty notification - here you can enqueue //your server-synchronization routine - asynchronously if possible } } 

如果你不打算使用任何“真实”的通知,你甚至不必费心解码消息。

如果你使用ApnsPHP,你的消息生成代码如下所示:

 $message = new ApnsPHP_Message($device_apns_token); $message->setText(''); $message->setSound(''); $message->setExpiry(3600); $push->add($message);