#import <PassKit/PassKit.h>
// convert base64 string to pkpass data
NSData *passData = [[NSData alloc] initWithBase64EncodedString:strEncodeData options:0];
NSLog(passData);
// init a pass object with the data
PKPass *pass = [[PKPass alloc] initWithData:passData];
NSLog(pass);
//init a pass library
PKPassLibrary *passLib = [[PKPassLibrary alloc] init];
//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];
}
I am tring to save passbook to ios wallet. I need to use base64 data instead of uri because of secure issue. The flow I assumed for this is like below
- get base64 string from the server.
- convert base64 to pkpass data with "initWithBase64EncodedString"
- save pkpass to wallet with "PKAddPassesViewController"
With above code, the progress is stop on second step with nil error, even the decoded base64 string is correct. So I cannot be sure the code after 2nd step will functionate without errors.
thanks for answer in advance.