我运行代码,如下所述。当我得到文件(NSData)时,出现以下错误:
"BOM could not extract archive: Couldn't read PKZip signature"
怎么了?有没有人遇到过这个问题,我该如何解决?
NSString *url = [res objectForKey:@"url"];
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]]; if (nil != data) {
//init a pass library
PKPassLibrary* passLib = [[PKPassLibrary alloc] init];
NSError *error;
//init a pass object with the data
PKPass *pass = [[PKPass alloc] initWithData:data error:&error];
if(error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil];
[alertView show];
}
//check if pass library contains this pass already
if([passLib containsPass:pass]) {
//pass already exists in library, show an error message
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Pass Exists" message:@"The pass you are trying to add to Passbook is already present." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
} else {
//present view controller to add the pass to the library
PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPass:pass];
[vc setDelegate:(id)self];
[self presentViewController:vc animated:YES completion:nil];
}
}