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];
}
}
While fetching for NSData from .pkpass file from the local path i am getting the NSData object is nil ...
can anyone help me thanks in advance.
PassKit
12.6k5 gold badges60 silver badges78 bronze badges
-
1check nsdata for nslog(@"%@" , nsData);Bajaj– Bajaj2012年10月11日 13:22:12 +00:00Commented Oct 11, 2012 at 13:22
1 Answer 1
If your NSData object is nil it means your dataWithContentsOfFile: call didn't work. Check that your filePath is valid - if it isn't, that's your problem.
answered Oct 11, 2012 at 13:22
lxt
31.3k5 gold badges81 silver badges83 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-objectivec