iOS报刊:推送通知不会在后台启动应用程序

我在应用程序中实现报摊function,尽pipe应用程序收到推送通知,但它并不以后台模式启动。
如果我点击通知提醒应用程序启动,我可以看到“内容可用”:1是存在于字典中,也是下载的问题,但该应用程序不会自动启动。

我已经添加到plist:

<key>UIBackgroundModes</key> <array> <string>newsstand-content</string> </array> 

和didFinishLaunchingWithOptions:

 [[NSUserDefaults standardUserDefaults]setBool: YES forKey:@"NKDontThrottleNewsstandContentNotifications"]; // for testing purposes [[NSUserDefaults standardUserDefaults] synchronize]; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeNewsstandContentAvailability )]; 

我也看到我的应用程序没有显示在设置 – >存储 – >自动下载(和其他杂志出现在那里)。

我错过了什么吗? 这应该在沙箱环境中工作吗?

一些澄清

  1. 如果您没有在仅包含可用内容的报亭有效内容中发送“提醒”:1,则通知中心将不会添加任何内容。
  2. 报亭通知启动应用程序并不意味着应用程序将前台(如果用户点击应用程序图标)。 这意味着如果应用程序不在后台,它将在后台由iOS启动 – >调用appDelegate的didFinishLaunchingWithOptions,应用程序应该检查是否通过在Newsstand队列中添加资源来安排下载的Newsstand通知。 资产path可以是NS有效载荷的一部分(提供<有效载荷限制256字节)

NSDictionary * payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if(payload && [[payload objectForKey:kContentAvailablePush] caseInsensitiveCompare:@“1”] == NSOrderedSame){NSLog(@“NS start notification due to NS notification”); }

确保UINewsstandApp = YES被设置在你的plist中

您必须注册报亭通知才能显示在“设置”中,并收到“报亭通知”。 要注册,添加到您的application:didFinishLaunchingWithOptions: ::

 // Add registration for newsstand notifications // In your application:didFinishLaunchingWithOptions: [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeNewsstandContentAvailability]; 

用户将被要求接受后台下载与否。

看看这个关于报亭应用的完整教程: http : //www.viggiosoft.com/blog/blog/2011/10/17/ios-newsstand-tutorial/

{"aps": {"badge": 1, "alert": "test","content-available":1}}这是一个正确的负载。 {"aps": {"badge": 1, "alert": "test"},"content-available":1}这是一个错误的载荷。

当内容可用在有效载荷中时,会发生这种情况:

  • 如果应用程序暂停,系统将把它带入后台
  • 如果应用程序被用户杀害没有任何反应 ,应用程序仍然在不运行

必须通过将警报消息添加到推送通知中来启动应用程序。

资源

http://samwize.com/2015/08/07/how-to-handle-remote-notification-with-background-mode-enabled/

但是这并不能解决你的问题。 作为解决方法,您可以使用后台提取,每隔一定的时间间隔唤醒应用程序。