我正在应用程序中实现报刊亭功能,尽管应用程序收到推送通知,但它不会在后台模式下启动。
如果我点击通知警报,应用程序将启动,我可以看到字典中存在“content-available”: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 )];
我还发现我的应用程序未显示在“设置”->“商店”->“自动下载”下(其他杂志也显示在那里)。
我错过了什么吗?这应该在沙箱环境中工作吗?
一些澄清
- 如果您没有在报亭负载中发送“警报”
其中只有 content-available:1 ,不会添加任何内容
通知中心。
- 报亭通知启动应用程序并不意味着该应用程序将进入前台(就像用户点击应用程序图标一样)。这只是意味着,如果应用程序不在后台,它将由 iOS 在后台启动 -> 调用 appDelegate 的 didFinishLaunchingWithOptions,其中应用程序应检查它是否是报亭通知,以通过在报亭队列中添加资源来安排下载。资产路径可以是 NS 有效负载的一部分(前提是
NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(payload && [[payload objectForKey:kContentAvailablePush] caseInsensitiveCompare:@"1"] == NSOrderedSame)
{
NSLog(@"由于 NS 通知而启动");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)