0
#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

  1. get base64 string from the server.
  2. convert base64 to pkpass data with "initWithBase64EncodedString"
  3. 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.

Nazik
  • 8,696
  • 27
  • 77
  • 123
epicsaga
  • 1
  • 2
  • I refered these links : http://stackoverflow.com/questions/16817346/receiving-passbooks-pkpass-from-url-without-webview and https://www.captechconsulting.com/blogs/ios-6-tutorial-integrating-passbook-into-your-applications – epicsaga Oct 30 '15 at 08:15
  • Have you confirmed that pass contained in the base64 string is valid and can be added to Passbook via a pkpass file or url? – Tomas McGuinness Oct 31 '15 at 06:19
  • I just put the base64 string generated manually with online tool(UTF-8 format). could I check that string is correct on xcode(object-c)? – epicsaga Nov 01 '15 at 09:24

1 Answers1

0

I know its late but i ran into the same problem after lot of research figure the issue is with initWithBase64EncodedString:passBase64 when base64 string decode from server response with mime type like:data:application/vnd.apple.pkpass;base6 NSData get nil. Maybe its a bug but if you use NSData+Base64 classes from https://github.com/l4u/NSData-Base64 its old but you can configure it to work with ARC and than convert data from base64 string to NSData problem goes away.

Muhammad Anum
  • 136
  • 16