“只有当用户启动应用程序以响应推送通知(例如,在锁定屏幕上或从通知中心滑动),或者它已经在运行时,您的应用程序才会收到推送通知。”
如果报刊亭通知(在有效负载中有 content-available:1),上述声明是不正确的。收到它后,iOS 在后台启动应用程序(如果未运行)并调用应用程序委托的 didFinishLaunchingWithOptions 方法。您可以检查启动选项字典的 UIApplicationLaunchOptionsRemoteNotificationKey 的值,以检查您的应用程序是否通过通知启动。
NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(payload && [[payload objectForKey:kContentAvailablePush] caseInsensitiveCompare:@"1"] == NSOrderedSame)
{
NSLog(@"app launched by Newsstand Remote notification. payload %@", payload);
[self scheduleNewsStandDownload:payload];
}
在方法 scheduleNewsStandDownload 中,您可以简单地获取托管内容的路径/日期等并将其添加到报亭队列中。下面是伪代码。
NKLibrary *nkLib = [NKLibrary sharedLibrary];
NKIssue *nkIssue = [nkLib issueWithName:<your content id>];
if(!nkIssue)
nkIssue = [nkLib addIssueWithName:<your content id> date:<your content date>];
NKAssetDownload *nkAssetDownloadGridCover = [nkIssue addAssetWithRequest:<urlRequest for the content>];
[nkAssetDownloadGridCover downloadWithDelegate:self];