NSString *filePath = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"freehugcoupon.pkpass"];
NSLog(@"Filepath = [%@]",filePath);
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSError *error;
if (data != nil) {
PKPass *pass = [[PKPass alloc] initWithData:data error:&error];
NSLog(@"Error = [%@]",[error localizedDescription]);
if([passLib containsPass:pass]) {
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];
[alertView release];
} else {
PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPass:pass];
vc.delegate = self;
[self presentViewController:vc animated:YES completion:nil];
[vc release];
[pass release];
}
}
从本地路径获取.pkpass文件中的NSData时,我得到的NSData对象是nil ...
任何人都可以帮助我 提前谢谢。答案 0 :(得分:1)
如果您的NSData
对象为nil
,则表示您的dataWithContentsOfFile:
电话无效。检查您的filePath
是否有效 - 如果不是,那就是您的问题。