Is it possible to cancel an NKAssetDownload?

2019-05-09 10:56发布

I have a magazine reader on the App Store. I'm implementing NewsstandKit features at the moment.

My app has this download workflow where users can cancel current downloads at anytime.

I want to enable users to purchase an in-app product and begin that download as a newsstand background download (magazines include multimedia so they are kind of big files) but still preserve that option of they had on previous versions where they could cancel downloads.

Is it possible to achieve this with NKAssetDownload? Or should I remove the whole NKIssue instead?

2条回答
再贱就再见
2楼-- · 2019-05-09 11:26

If you remove an issue, corresponding downloads will be canceled.

NKIssue *issue = [[NKLibrary sharedLibrary] issueWithName:editionName]; 
if (issue)
    [[NKLibrary sharedLibrary] removeIssue:issue];
查看更多
做个烂人
3楼-- · 2019-05-09 11:46

You should use this method on the asset :

- (void)removeIssue:(NKIssue *)issue

// Remove asset
[[NKLibrary sharedLibrary] removeIssue:[[NKLibrary sharedLibrary]
                           issueWithName:self.issues[indexPath.row][@"Name"]]];

Description from Apple documentation :
Removes the specified issue from the newsstand content library. When an issue is removed, any data at the file-system location identified by the issue’s content URL (accessed through the contentURL property of NKIssue) is deleted from disk. If you have issue content elsewhere in the application sandbox, it’s your responsibility to clean it up. Calling this method also cancels any asset downloads for that issue that are underway.

Source : http://developer.apple.com/library/ios/documentation/StoreKit/Reference/NKLibrary_Class/NKLibrary/NKLibrary.html#//apple_ref/doc/uid/TP40010835-CH2-SW2

查看更多
登录 后发表回答