我正在开发一个快速应用的存折,我面临着一个奇怪的问题。 随机地,我从我的服务器下载的存折已损坏(相同的下载可能是好的或损坏的。)
以下是代码:
func openPass(pass: PKPass)
{
let passname = "Benight Ticket"
var passcontroller = PKAddPassesViewController(pass: pass)
passcontroller.delegate = self
self.presentViewController(passcontroller, animated: true, completion: nil)
}
func getTicketPassbook()
{
let TicketID: String = "2gBOZqWwNj"
let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: sessionConfig, delegate: nil, delegateQueue: nil)
let request = NSMutableURLRequest(URL: NSURL(string: "https://exemple.com/index.php")!)
request.HTTPMethod = "POST"
let postString: String = "ObjectId=" + TicketID + "&authKey=\"exemple\""
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = session.dataTaskWithRequest(request, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in
println("response = \(response)")
if (error == nil) {
// Success
let statusCode = (response as! NSHTTPURLResponse).statusCode
if (statusCode == 200)
{
println("Success: \(statusCode)")
var pkfile : NSData = NSData(data: data)
var pass: PKPass = PKPass(data: pkfile, error: nil)
self.openPass(pass)
}
// This is your file-variable:
// data
}
else {
// Failure
println("Faulure: %@", error.localizedDescription);
}
})
task.resume()
}
错误如下:2015-08-22 16:18:28.328应用程序[10302:1018965] BOM无法提取存档:无法读取PKZip签名
其他时候它的确有效......它确实在随机时间工作或失败......
编辑:Sometis我也有以下错误:2015-08-23 01:19:19.483 Benight [3467:994898]无效数据错误读取传递pass.com.apple.demo / 8j23fm3。提供的passTypeIdentifier或teamIdentifier可能与您的证书不匹配,或者无法验证证书信任链。 致命错误:在解包可选值时意外发现nil