2012-10-04 19 views
-1

如何在我的Web服務器上生成Pass,然後將其下載到Xcode中。 在xcode上,我試圖生成一個通行證,然後將其添加到我的存摺錢包。代碼:如何在我的Web服務器上生成Pass,然後在Xcode中下載它。

NSString* passFile = @"http://pass.keatonburleson.com/gen.php?name=128keaton"; 

//3 
NSData *passData = [NSData dataWithContentsOfFile:passFile]; 

//4 
NSError* error = nil; 
PKPass *newPass = [[PKPass alloc] initWithData:passData 
             error:&error]; 
//5 
if (error!=nil) { 
    [[[UIAlertView alloc] initWithTitle:@"Passes error" 
           message:[error 
             localizedDescription] 
           delegate:nil 
         cancelButtonTitle:@"Ooops" 
         otherButtonTitles: nil] show]; 
    return; 
} 

//6 
PKAddPassesViewController *addController = 
[[PKAddPassesViewController alloc] initWithPass:newPass]; 

    [self presentViewController:addController 
        animated:YES 
       completion:nil]; 

所以基本上,我的錯誤是'痕跡'和崩潰。 更新:感謝Caleb,沒有更多的跟蹤錯誤! 不幸的是,我收到'Pass isnt valid error!' :( 最新更新的代碼:

NSString* passFile = @"http://pass.keatonburleson.com/gen.php?name=128keaton"; 
NSURL *url = [NSURL URLWithString:passFile]; 
//3 
NSData *passData = [NSData dataWithContentsOfURL:url]; 

//4 
NSError* error = nil; 
PKPass *newPass = [[PKPass alloc] initWithData:passData 
             error:&error]; 

BG信息:

我的web服務器包含生成passkit通,並顯示下載像PkPass PHP腳本如果你在Mac或iPhone你可以進入passFile的URL,它會顯示一個有效的通行證,我想我的問題是,它試圖下載一個鏈接文件,當它真的產生一個自動下載它時,我可能需要編輯一些服務器代碼, 'saved'pkpass on my webserver。但是,我寧願不這樣做。

+1

你的問題是什麼?我看到的只是一些代碼。我發現你是新來的 - 你應該真正閱讀[faq]來學習如何在這裏有效地提問。 – Caleb

回答

0

您應該可能正在使用-dataWithContentsOfURL:因爲這就是你所提供的。第二行之後是passData == nil?如果是的話,那可能是你的問題。

注:的PKPass文檔說,你應該檢查的詳細信息控制檯如果從-initWithData:error: GT的錯誤,所以看看,讓我們知道你發現了什麼。

更新:

My webserver contains a PHP script which generates a passkit pass and displays it for download like a PkPass. If you are on a mac or iPhone you can go to the passFile URL and it will display a valid pass.

除非你的服務器檢測到客戶端,並決定基於什麼送回來,這是不太可能,顯示通相同的URL返回通文件本身。看看你收到的數據的內容,看看它是否有效。否則,您需要調整您的服務器或使用其他網址。

+0

好吧!謝謝!但是,現在我有'通不了'錯誤。所以,最新的代碼是這樣的:NSString * passFile = @「http://pass.keatonburleson.com/gen.php?name=128keaton」; NSURL * url = [NSURL URLWithString:passFile]; // 3 NSData * passData = [NSData dataWithContentsOfURL:url]; // 4 NSError * error = nil; PKPass * newPass = [[PKPass alloc] initWithData:passData error:&error]; – Keaton

+0

編輯您的問題並在其中添加代碼 - 在評論中閱讀代碼並不容易。當你在這裏,請澄清你的問題。 SO的部分價值在於質量問題(和答案)可以幫助未來的讀者,而不僅僅是OP。 – Caleb

+0

好的,謝謝我修好!不是這個問題,問題 – Keaton

相關問題