用户退出应用后我们如何恢复下载,而不仅仅是放入后台?
我的代码看起来像这样开始下载,我希望能够在这里确定问题是否可以恢复。
NSMutableURLRequest *nkRequest = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:30.0];
NKLibrary *library = [NKLibrary sharedLibrary];
NKIssue *issue = [library addIssueWithName:[downloadInfo objectForKey:kPackageID] date:[NSDate date]];
[[NKLibrary sharedLibrary] setCurrentlyReadingIssue:[[NKLibrary sharedLibrary] issueWithName:[downloadInfo objectForKey:kPackageID]]];
NKAssetDownload *asset = [issue addAssetWithRequest:nkRequest];
[asset setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:info,@"info", nil]];
[asset downloadWithDelegate:self];
答案 0 :(得分:3)
嗯,看起来很简单。我正在做的方式(以及Apple似乎如何做)是将以下代码放在AppDelegate方法应用程序中:didFinishLaunchingWithOptions:
// Get the Library
NKLibrary *nkLib = [NKLibrary sharedLibrary];
// Loop through all 'queued' NKAssetDownloads and resume with a delegate
for(NKAssetDownload *asset in [nkLib downloadingAssets])
{
[asset downloadWithDelegate:yourDownloadDelegate];
}
这应该就是你需要做的一切。在WWDC 2011的第504届会议上简要提到了这一点。该视频和幻灯片是报刊套件的好参考。我强烈建议你观看/阅读。这对我帮助很大。祝你好运!