I simply trying to add my passbook without sharing via email. How i can add my passbook on click button?
asked Oct 27, 2014 at 12:46
Boris Kuzevanov
1,3021 gold badge14 silver badges21 bronze badges
1 Answer 1
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
Flexicoder
8,5615 gold badges45 silver badges58 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Boris Kuzevanov
What i need to import?
lang-objectivec