Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passbook generates PKPass error

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.

like image 335
Dracuuula Avatar asked Oct 31 '22 22:10

Dracuuula


1 Answers

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.

like image 74
PassKit Avatar answered Nov 15 '22 06:11

PassKit