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

1 回答 1

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 的 Session 504 下被简要提及。该视频和幻灯片是很好的 Newsstand-Kit 参考资料。我强烈建议您观看/阅读。这对我帮助很大。祝你好运!

于 2012-01-11T17:59:34.203 回答