2013-07-22 4 views
3

아래에 설명 된대로 코드를 실행합니다. 파일 (NSData)을 받으면 다음 오류가 표시됩니다.오류 통장 - PKZip 서명

"BOM could not extract archive: Couldn't read PKZip signature" 

무슨 일입니까? 누구든지이 문제가 있었고 어떻게 해결할 수 있습니까?

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]; 
    } 
} 
+1

소리는 .pkpass 번들에 문제가 있으며 사용자 코드가 아닙니다. Safari, 메일 첨부 또는 OSX의 패스 뷰어를 통해 액세스 할 때 .pkpass 번들 가져 오기가 올바르게 실행됩니다. 사용중인 iOS SDK 버전은 무엇입니까? – PassKit

답변

0

connectionDidReceiveData 메서드에서 오는 NSData 개체를 사용한다고 가정하면이 오류가 발생합니다. connectionDidFinishLoading까지 NSData 객체를 누적해야합니다.

은 다음과 같이해야합니다 :

-(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

문제는 라인

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

다운로드 된 데이터가 손상입니다.

0

전자 메일/Safari를 통해 패스를 추가 할 수있는 경우 문제는 NSData 개체 때문입니다.

필자의 경우 pkpass 파일 base64 String 값이 NSData 객체로 변환 된 장치에 수신되었습니다. PK 패스 개체가 내 패스를 읽을 수있었습니다. 다음은 사용 된 코드입니다.

// 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"); 
} 

희망이 있습니다.