NKAssetDownload addAssetWithRequest apns sigabrt

时间:2012-02-17 10:08:36

标签: objective-c ios push-notification newsstand-kit

我通常能够解决为什么发生sigabrts,但我完全陷入了这个问题。我正在通过远程通知启动应用程序,这一切都正常,直到它得到这段代码:

NKIssue *issueNK = [[NKLibrary sharedLibrary] issueWithName:[issueId stringValue]]; 
if (issueNK == nil) {
    issueNK = [[NKLibrary sharedLibrary] addIssueWithName:[issueId stringValue] date:[NSDate date]];  
}

NSMutableDictionary* settings = [[[NSMutableDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"]] autorelease];
NSURL *downloadURL = [NSURL URLWithString:
                      [NSString stringWithFormat:[settings objectForKey:@"IssueBundleUrl"], [issue.issueId intValue]]];
NSURLRequest *request = [NSURLRequest requestWithURL:downloadURL];
NKAssetDownload *assetDownload = [issueNK addAssetWithRequest:request]; //sigabrt on this line
[assetDownload downloadWithDelegate:issueListViewController];

在调试器中,issueNK和请求似乎都很好,不是零或任何东西。

任何想法?感谢。

1 个答案:

答案 0 :(得分:1)

我猜你在该行上看到异常的唯一原因是,问题是否已经下载或正在下载。因此,您需要先检查问题的状态:

NKIssue *issueNK = [[NKLibrary sharedLibrary] issueWithName:[issueId stringValue]]; 
if (issueNK == nil) {
    issueNK = [[NKLibrary sharedLibrary] addIssueWithName:[issueId stringValue] date:[NSDate date]];  
}

if ([issueNK status] != NKIssueContentStatusNone)
    return;

NSMutableDictionary* settings = [[[NSMutableDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"]] autorelease];
NSURL *downloadURL = [NSURL URLWithString:
                  [NSString stringWithFormat:[settings objectForKey:@"IssueBundleUrl"], [issue.issueId intValue]]];
NSURLRequest *request = [NSURLRequest requestWithURL:downloadURL];
NKAssetDownload *assetDownload = [issueNK addAssetWithRequest:request];
[assetDownload downloadWithDelegate:issueListViewController];