Question

My App deals with downloading coupons & save into Passbook. But each time I download a different coupon, file is getting replaced on Passbook.

Below given is my code to add my coupons to Passbook :

Step 1 : Added 'PassKit' framework to the project & imported the same.

Step 2 : Added 'PKAddPassesViewControllerDelegate' on my h file.

Step 3 :

- (void) generatePass {

if (![PKPassLibrary isPassLibraryAvailable]) {
    [[[UIAlertView alloc] initWithTitle:@"Error"
                                message:@"PassKit not available"
                               delegate:nil
                      cancelButtonTitle:@"Pitty"
                      otherButtonTitles: nil] show];
    return;
}
else {

    NSData *passData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://(url).pkpass"]];

    NSError* error = nil;
    PKPass *newPass = [[PKPass alloc] initWithData:passData
                                             error:&error];
    if (error!=nil) {
        [[[UIAlertView alloc] initWithTitle:@"Passes error"
                                    message:[error
                                             localizedDescription]
                                   delegate:nil
                          cancelButtonTitle:@"Ooops"
                          otherButtonTitles: nil] show];
        return;
    }

    PKAddPassesViewController *addController =
    [[PKAddPassesViewController alloc] initWithPass:newPass];

    addController.delegate = self;
    [self presentViewController:addController
                       animated:YES
                     completion:nil];
}
}
Was it helpful?

Solution

Passbook indexes passes by serialNumber and passTypeIdentifier. When adding a pass, if a pass with a matching serialNumber and passTypeIdentifier already exists in a user's pass library, that pass will be overwritten by the pass being added.

To add multiple passes for the same passTypeIdentifer you will have to generate a unique serialNumber for each new pass.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top