我正在开发一个支持存折的快速应用程序,但我遇到了一个奇怪的问题。随机地,我从我的服务器下载的存折已损坏(相同的下载可能是好的或损坏的)。
这是代码:
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 Application[10302:1018965] BOM 无法提取存档:无法读取 PKZip 签名
而其他时候它工作......它真的是在随机的时间工作或失败......
编辑:Sometis 我也有以下错误:2015-08-23 01:19:19.483 Benight[3467:994898] Invalid data error reading pass pass.com.apple.demo/8j23fm3. 提供的 passTypeIdentifier 或 teamIdentifier 可能与您的证书不匹配,或者无法验证证书信任链。致命错误:在展开可选值时意外发现 nil