首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误存折- PKZip签名

错误存折- PKZip签名
EN

Stack Overflow用户
提问于 2013-07-22 22:06:24
回答 3查看 1.8K关注 0票数 4

我运行代码,如下所示。当我获取文件(NSData)时,出现以下错误:

代码语言:javascript
复制
"BOM could not extract archive: Couldn't read PKZip signature"

这是怎么回事?有没有人遇到过这个问题,我该如何解决?

代码语言:javascript
复制
    NSString *url = [res objectForKey:@"url"];

    NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];    if (nil != data) {

    //init a pass library
    PKPassLibrary* passLib = [[PKPassLibrary alloc] init];

    NSError *error;

    //init a pass object with the data
    PKPass *pass = [[PKPass alloc] initWithData:data error:&error];

    if(error) {

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil];
    [alertView show];

    }

    //check if pass library contains this pass already
    if([passLib containsPass:pass]) {

        //pass already exists in library, show an error message
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Pass Exists" message:@"The pass you are trying to add to Passbook is already present." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];

    } else {

        //present view controller to add the pass to the library
        PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPass:pass];
        [vc setDelegate:(id)self];
        [self presentViewController:vc animated:YES completion:nil];
    }
}
EN

回答 3

Stack Overflow用户

发布于 2014-06-26 20:47:46

假设您尝试使用来自connectionDidReceiveData方法的NSData对象,这是错误的。您应该在connectionDidFinishLoading之前累积NSData对象。

你应该这样做:

代码语言:javascript
复制
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    if (self.passData != nil) {
        [self.passData appendData:data];
    }
    else {
        self.passData = [NSMutableData dataWithData:data];
    }
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSError *error;
    PKPass *pass = [[PKPass alloc] initWithData:self.passData error:&error];
    //add pass
    self.passData = nil;
}
票数 0
EN

Stack Overflow用户

发布于 2015-03-27 15:49:01

问题出在这条线上

代码语言:javascript
复制
//init a pass object with the data
    PKPass *pass = [[PKPass alloc] initWithData:data error:&error];

下载的数据已损坏。

票数 0
EN

Stack Overflow用户

发布于 2015-05-20 16:57:48

如果您能够通过电子邮件/Safari添加通行证,那么问题就出在NSData对象上。

在我的例子中,pkpass文件的base64字符串值是在我转换成NSData对象的设备上接收到的。PKPass对象能够读取我的通行证。下面是我使用的代码:

代码语言:javascript
复制
// dictionary contains base64string values of the pkpass file.
for (NSString *key in [dictionary allKeys])
{
    NSError *error;
    NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:[dictionary valueForKey:key] options:0];
    NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];

    PKPass *pass = [[PKPass alloc] initWithData:decodedData error:&error];
    [arrPasses addObject:pass];

}
if ([arrPasses count] > 0)
{
    PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPasses:arrPasses];
    [self presentViewController:vc animated:YES completion:nil];
}
else
{
    NSLog(@"Passes not found");
}

希望这能有所帮助!!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17789671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档