iOS书报摊:推送通知不会在后台启动应用程序 [英] iOS newsstand: push notification does not launch the app in background

查看:92
本文介绍了iOS书报摊:推送通知不会在后台启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在应用程序中实现报亭功能,尽管该应用程序收到推送通知,但它不是在后台模式下启动.
如果我点击通知警报,该应用程序将启动,并且我会看到内容可用":1存在于词典中,并且该问题也已下载,但该应用程序不会自动启动.

I'm implementing newsstand features in an application and though the app receives the push notification it does not start in background mode.
If I tap the notification alert the the app starts and I can see "content-available":1 is present in the dictionary and also the issue is downloaded, but the app is not automatically launched.

我已添加到plist:

I've added to the plist:

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

,并执行didFinishLaunchingWithOptions:

and to didFinishLaunchingWithOptions:

[[NSUserDefaults standardUserDefaults]setBool: YES forKey:@"NKDontThrottleNewsstandContentNotifications"]; // for testing purposes
    [[NSUserDefaults standardUserDefaults] synchronize];

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeNewsstandContentAvailability )];

我还看到我的应用程序未显示在设置"->商店"->自动下载"下(其他杂志出现在其中).

I also see that my app is not shown under Settings -> Store -> Automatic Downloads (and other magazines appears there).

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

Am I missing something? Is this supposed to work in sandbox environment?

推荐答案

一些说明

  1. 如果您未在报亭有效载荷中发送警报", 仅内容可用:1,不会添加任何内容 通知中心.
  2. 报亭通知启动应用程序并不意味着该应用程序会出现在前台(就像用户在应用程序图标上轻按一样).这只是意味着,如果该应用程序不在后台,它将由iOS在后台启动->调用appDelegate的didFinishLaunchingWithOptions,在此应用程序应检查是否是报亭通知,以通过在报亭队列中添加资产来安排下载.资产路径可以是NS有效负载的一部分(提供的有效负载限制为<256个字节)
  1. If you do not send "alert" in your Newsstand payload which has only content-available:1 in it, nothing will get added in notification center.
  2. Newsstand notification launch application does not mean the app will come to foreground (as in if user tapped over app icon). It just mean that if the app is not in background, it will get launched by iOS in background -> didFinishLaunchingWithOptions of appDelegate is called, where app should check if it is a Newsstand notification to schedule the download by adding assets in Newsstand queue. The asset paths can be part of NS payload (provided < payload limit 256 bytes)

NSDictionary *有效载荷= [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

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

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

这篇关于iOS书报摊:推送通知不会在后台启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆