4

我正在应用程序中实现报亭功能,虽然应用程序收到推送通知,但它并没有在后台模式下启动。
如果我点击通知警报,应用程序将启动,我可以看到字典中存在“内容可用”: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 )];

我还看到我的应用程序未显示在“设置”->“商店”->“自动下载”下(其他杂志出现在那里)。

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

4

5 回答 5

2

一些说明

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

NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if(payload && [[payload objectForKey:kContentAvailablePush] caseInsensitiveCompare:@"1"] == NSOrderedSame) { NSLog(@"由于 NS 通知而启动"); }

于 2012-09-01T05:42:00.823 回答
1

您必须注册报亭通知才能显示在“设置”中并接收“报亭通知”。要注册,请将其添加到您的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/

于 2013-01-25T09:03:21.080 回答
0

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

于 2013-03-02T17:58:33.693 回答
0

确保在您的 plist 中设置了 UINewsstandApp = YES

于 2013-01-13T18:15:20.657 回答
-1

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

  • 如果应用程序被暂停,系统会将其带入后台
  • 如果应用程序被用户杀死,则不会发生任何事情并且应用程序仍处于未运行状态

必须有一个用户操作来启动应用程序,本质上是通过将警报消息添加到推送通知中。

资源

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

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

于 2015-12-09T09:53:38.700 回答