PKPass错误“无法读取传递,因为它无效。”

时间:2017-06-28 07:58:10

标签: ios iphone swift swift3 passbook

获取错误

  

BOM无法提取存档:无法读取PKZip签名

     

错误可选(错误域= PKPassKitErrorDomain代码= 1“通行证   无法阅读,因为它无效。“   UserInfo = {NSUnderlyingError = 0x1570e200 {错误   Domain = PKPassKitErrorDomain Code = 1“(null)”},   NSLocalizedDescription =无法读取传递,因为它不是   有效。})

检查此代码

var myPass : PKPass?

self.myPass = PKPass(data: pageData, error: &errorPass)

这是我的代码

   if PKPassLibrary.isPassLibraryAvailable()
        {
            DispatchQueue.main.async {
                do {
                    let pageData = try Data.init(contentsOf: URL(string: mainURL)!)

                    var errorPass : NSError?
                    self.myPass = PKPass(data: pageData, error: &errorPass)

                    MBProgressHUD.hideAllHUDs(for: self.mainScrollview, animated: true)
                    if errorPass == nil
                    {
                        let passview = PKAddPassesViewController(pass: self.myPass!)
                        passview.delegate = self
                        self.present(passview, animated: true, completion: nil)

                    }
                    else
                    {
                        print("Error \(errorPass)")
                    }


                } catch let e as NSError {
                    print(e.localizedDescription)
                    MBProgressHUD.hideAllHUDs(for: self.mainScrollview, animated: true)
                    self.view.makeToast("Something went wrong with error : \(e.localizedDescription)")
                }
            }
        }

我的PKPass格式是

{
        "formatVersion" : 1,
        "passTypeIdentifier" : "pass.com.pek.pek",
        "serialNumber" : "'.$booking_id.'",
        "teamIdentifier" : "ABC00001",
        "webServiceURL" : "https://peek.com/ba/pass/",
        "authenticationToken" : "kjghadsfgghjgjhfadisfgyfgdsyfuya",

        "barcode" : {
          "message" : "123456789",
          "format" : "PKBarcodeFormatQR",
          "messageEncoding" : "iso-8859-1"
        },
        "organizationName" : "Peek Inc.",
        "description" : "Room",
        "foregroundColor" : "rgb(255, 255, 255)",
        "backgroundColor" : "rgb(0, 200, 83)",
        "eventTicket" : {
          "primaryFields" : [
            {
              "key" : "event",
              "label" : "Name",
              "value" : "'.$restaurant_name.'"
            }
          ],
              "secondaryFields" : [
            {
              "key" : "eventtime",
              "label" : "Date",
              "value" : "'.$slot_date.'"
            }
          ],
              "auxiliaryFields" : [
            {
              "key" : "bookingid",
              "label" : "BOOKING ID",
              "value" : "'.$booking_id.'"
            },
            {
              "key" : "noofperson",
              "label" : "NO OF TICKETS",
              "value" : "'.$no_of_tickets.'",
              "textAlignment" : "PKTextAlignmentCenter"
            }
          ]
        }
      }

先谢谢

1 个答案:

答案 0 :(得分:0)

我曾参与PKPass并面临另一个问题。但是我提到了所有步骤,通过拉动刷新和通过推送通知生成传递和更新传递。 steps...

希望这有帮助!