Newsstand resume download after the App closed by user Fully

删除回忆录丶 提交于 2020-01-03 05:23:09

问题


How do we resume a download after the user quits the app, not just put into background?

My code looks like this to start the download initially, I want to be able to identify here as to if the issue can be resumed.

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

回答1:


Well, it seems to be quite simple. The way I am doing (and how it seems Apple says to do it) is by putting the following code in the AppDelegate method application: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];
}

That should be all you need to do. This was briefly mentioned at WWDC 2011 under Session 504. That video and slides are good Newsstand-Kit references. I would highly recommend you watch/read that. It helped me a lot. Good luck!



来源:https://stackoverflow.com/questions/8583652/newsstand-resume-download-after-the-app-closed-by-user-fully

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!