以下に概説するように、コードを実行します。ファイル (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];
}
}