2
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 ...

任何人都可以帮助我提前谢谢。

4

1 回答 1

1

如果您的NSData对象是nil,则意味着您的dataWithContentsOfFile:呼叫无效。检查您的filePath是否有效 - 如果不是,那是您的问题。

于 2012-10-11T13:22:22.413 回答