5
votes

I add passbook in my app, when the system is iOS6.0 it work correctly.When the system is iOS7.1 it appear an error.

enter image description here

I check the code found that

PKPass *newPass = [[PKPass alloc] initWithData:passData error:&error];

When generate PKPass in iOS6.0 get a correct PKPass,when the system is iOS7.1 get a nil.

The error contain message is that:

Error Domain=PKPassKitErrorDomain Code=1 "The pass cannot be read because it isn’t valid." UserInfo=0x175cd2f0 {NSUnderlyingError=0x175c2c10 "more than one field has the key 'phone'. Field keys must be unique.", NSLocalizedDescription=The pass cannot be read because it isn’t valid.}

The data of the passbook i get it from server.Code like follow

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[self.connectionData appendData:data];
}

After get the data write to file,code like follow:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES);
NSString* filePath  = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"pk.pkpass"];

if ([self.connectionData writeToFile:filePath atomically:YES]) {

    if (![PKPassLibrary isPassLibraryAvailable]) {

        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error"
                                                     message:@"PassKit not available"
                                                    delegate:nil
                                           cancelButtonTitle:@"Pitty"
                                           otherButtonTitles:nil];
        [alert show];
        [alert release];

        return;
    }
}

After write to file i want to show it,code like follow:

    NSString* passFile = [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:name];

NSString * newPassStr = [[NSString alloc] initWithContentsOfFile:passFile encoding:NSUTF8StringEncoding error:nil];

NSData *passData = [NSData dataWithContentsOfFile:passFile];

NSError* error = nil;
PKPass *newPass = [[PKPass alloc] initWithData:passData error:&error];

Then when i get the PKPass *newPass appear the error in iOS7.1. In iOS6 it's OK.

Anyone can tell me the reason?A lot of thanks.

1
Most likely you have not included a signing date in your signature. Can you post the .pkpass bundle? - PassKit
@PassKit how to post the pkpass? - Dracuuula
Put it online somewhere and post a link. How are you populating your passData variable? - PassKit
@PassKit i post it here pan.baidu.com/s/1ntHQPJj thank you! - Dracuuula
There's nothing wrong with the pass, so most likely your objective-c code. How are you populating your passData variable? What information is contained in your error variable? - PassKit

1 Answers

2
votes

Your error message is telling you everything you need to know.

You have duplicate keys in your pass.json. Your backFields array and your auxiliaryFields array both contain an item with the key phone. According to the Passbook Package Format Reference, field keys have to be unique.

I notice that this pass has been generated using Passsource. You might want to let kudit (the Passsource developer) know because his service should not allow such a pass to be generated.