2011-12-21 59 views
0

如何在用户退出应用程序后恢复下载,而不仅仅是放入后台?应用程序在用户关闭后报亭恢复下载完全

我的代码看起来像这样开始下载最初,我想能够在这里确定问题是否可以恢复。

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]; 

回答

3

好吧,它似乎很简单。我做的(以及它是如何似乎苹果公司称这样做)的方法是把下面的代码在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下简要提及。该视频和幻灯片是很好的报亭套件参考。我强烈建议你观看/阅读。这对我帮助很大。祝你好运!

相关问题