Passbook generates PKPass error
ios, ios6, ios7, objective-c, passbook
Solution
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.
Problem
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. 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.