Passbook会生成PKPass错误

时间:2014-05-29 05:48:16

标签: ios objective-c ios7 ios6 passbook

我在我的应用程序中添加了存折,当系统是iOS6.0时,它正常工作。当系统是iOS7.1时,它出现错误。

enter image description here

我检查找到的代码

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

在iOS6.0中生成PKPass时获取正确的PKPass,当系统为iOS7.1时获取nil。

错误包含的信息是:

错误Domain = PKPassKitErrorDomain Code = 1“无法读取传递,因为它无效。” UserInfo = 0x175cd2f0 {NSUnderlyingError = 0x175c2c10“多个字段的密钥为'phone'。字段键必须是唯一的。”,NSLocalizedDescription =无法读取该密码,因为它无效。}

存折的数据我从server.Code得到它,如下面的

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

获取数据写入文件后,代码如下:

    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;
    }
}

写入文件后我想显示它,代码如下:

    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];

然后当我得到PKPass * newPass时出现iOS7.1中的错误。在iOS6中没关系。

任何人都可以告诉我原因吗?非常感谢。

1 个答案:

答案 0 :(得分:1)

您的错误消息告诉您需要知道的一切。

你的pass.json中有重复的键。您的backFields数组和auxiliaryFields数组都包含一个键为phone的项。根据{{​​3}},字段键必须是唯一的。

我注意到此传递是使用Passsource生成的。您可能想让Passbook Package Format Reference(Passsource开发人员)知道,因为他的服务不应该允许生成这样的传递。