1

I simply trying to add my passbook without sharing via email. How i can add my passbook on click button?

EsbenB
3,43629 silver badges46 bronze badges
asked Oct 27, 2014 at 12:46

1 Answer 1

4

This code assumes that you know how to create the pass in the first place...

NSError * passerror;
PKPass * pass = [[PKPass alloc] initWithData:data error:&passerror];
if(!pass) {
 UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Pass Failed" message:@"Sorry there was a problem creating your Passbook." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
 [alertView show];
 return;
}
//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:@"Pass is already in Passbook." 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];
}

EDIT You'll need to import

#import <PassKit/PassKit.h>
answered Oct 27, 2014 at 13:04
Sign up to request clarification or add additional context in comments.

1 Comment

What i need to import?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.