![](/img/trans.png)
[英]Download file in background when app is inactive without newsstand in iOS
[英]IOS Newsstand background troubleshouting
我正在启动一个报亭应用程序,首先我正在测试所有框架以查看谁都能正常工作。 在前台时,我已经下载了由通知触发的问题。 但是我不知道如何在后台下载,或者至少我缺少一些东西...这是我添加到plist的内容:
该应用程序是针对IOS 5 ...这里是我的代码...我当然也实施了三个URLConection方法NKAssetDownload
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([launchOptions objectForKey:UIApplicationLaunchOptionsNewsstandDownloadsKey] || [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
NKLibrary *nkLib = [NKLibrary sharedLibrary];
for(NKAssetDownload *asset in [nkLib downloadingAssets]) {
[asset downloadWithDelegate:self];
}
}else{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeNewsstandContentAvailability
)];
}
[[NSUserDefaults standardUserDefaults]setBool: YES forKey:@"NKDontThrottleNewsstandContentNotifications"];
[[NSUserDefaults standardUserDefaults] synchronize];
return YES;
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"didReceiveRemoteNotification");
if (userInfo) {
NKIssue *issue4 = [[NKLibrary sharedLibrary] issueWithName:@"01_Primera"];
if (!issue4) {
issue4= [[NKLibrary sharedLibrary] addIssueWithName:@"01_Primera" date:[NSDate date]];
}
if([issue4 status]==NKIssueContentStatusNone) {
NSURL *downloadURL = [NSURL URLWithString:@"http://www.viggiosoft.com/media/data/blog/newsstand/magazine-4.pdf"];
NSURLRequest *req = [NSURLRequest requestWithURL:downloadURL];
NKAssetDownload *assetDownload = [issue4 addAssetWithRequest:req];
[assetDownload downloadWithDelegate:self];
}
}
}
我缺少什么,还有其他多余的代码吗? 请帮忙。
如果您正在尝试在iOS7上通过内容为available:1的通知唤醒应用程序(将其刷掉后),则它存在一个错误: 请在此处 和此处 阅读 (使用您的dev帐户登录) 。 如果您要测试的设备尚未更新,则它应该可以在iOS 5-6上运行。
您还需要在Info.plist中输入一个密钥: 所需的后台模式-报亭内容
最后,在代码中,我认为您应该在didFinishLaunchingWithOptions中进行一些更改:
if ([launchOptions objectForKey:UIApplicationLaunchOptionsNewsstandDownloadsKey] || [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { [self handleNotification:launchOptions]; } //...other code... //This code can be the same as with didReceiveRemoveNotification -(void) handleNotification:(NSDictionary*)userInfo{ //check userInfo for "content-available" key //if there is content-available:1 check for an issue_id/content_id in the rest of the notification payload (userInfo), and download the issue }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.