ios - PKPass 错误 "The pass cannot be read because it isn’ t 有效。”

标签 ios iphone swift swift3 passbook

获取错误

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

Error Optional(Error Domain=PKPassKitErrorDomain Code=1 "The pass cannot be read because it isn’t valid." UserInfo={NSUnderlyingError=0x1570e200 {Error Domain=PKPassKitErrorDomain Code=1 "(null)"}, NSLocalizedDescription=The pass cannot be read because it isn’t valid.})

检查这段代码

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"
            }
          ]
        }
      }

提前致谢

最佳答案

我曾从事 PKPass 工作,但面临另一个问题。但我在这里提到了通过拉动刷新和推送通知生成通行证和更新通行证的所有步骤。 steps...

希望这对您有所帮助!

关于ios - PKPass 错误 "The pass cannot be read because it isn’ t 有效。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44796758/

相关文章:

ios - 如何查看 XCUIElement 树?

iPhone - TableView 编辑并且仍然可以选择

iphone - touchesBegan 和 touchesMoved

ios - 从 SwiftLint 配置中排除 Pod

ios - 没有这样的模块 UIintedButton

ios - 当设置为 "Link All"时,DependencyService.Get 返回 null

iphone - 没有音频硬件可用时调用 AudioUnitInitialize()

ios - 从 podspec 或 info.plist 中检索 pod 版本到代码中

ios - 无法通过 cellForRowAtIndexPath 获取单元格

ios - 有没有什么方法可以以编程方式发送短信,而无需打开 iPhone 中的默认短信应用程序?