3

My app has a requirement to add multiple passes (a group of the pass) in apple wallet

I have PKAddPassesViewController, and it has a method to add multiple passes but after adding in it, it shows only 1 pass.

//destinationURLs are download file URL
let pkfile1 : Data = try! Data(contentsOf: destinationURL1)
let pkfile2 : Data = try! Data(contentsOf: destinationURL2)
var pkPasses = [PKPass]()
let pass : PKPass = PKPass(data: pkfile1 as Data, error: nil)
let pass1 : PKPass = PKPass(data: pkfile2 as Data, error: nil)
pkPasses.append(pass)
pkPasses.append(pass1)

let vc = PKAddPassesViewController(passes: pkPasses) as PKAddPassesViewController
vc.delegate = self
appDelegate.window?.rootViewController!.present(vc, animated: true, completion: nil)

With this code, I get only 1 proper formatted graph

my screenshot of PKAddPassesViewController's passes

rmaddy
  • 314,917
  • 42
  • 532
  • 579
SmarterSusheel
  • 169
  • 2
  • 15

1 Answers1

1

Looking at your code, pass and pass1 contain the same data.

Your comment above explains why you are only seeing one pass, because passes are uniquely indexed by certificate and serial number.

Wallet won't allow 2 passes with the same index, so your second pass is most likely overwriting your first. Use a different serial number when generating your second pass and you will have no problem.

PassKit
  • 12,231
  • 5
  • 57
  • 75
  • sorry for added same pkfile by mistake but both passes have different pkpass,kindly check my edited my code. – SmarterSusheel Apr 22 '19 at 13:56
  • But if they both have the same serial number you will only see one card in the wallet. – PassKit Apr 22 '19 at 13:56
  • I think serial number is unique for an application. am i right? – SmarterSusheel Apr 22 '19 at 14:09
  • No, the serial number needs to be unique for the pass. When you update a pass, Wallet uses a composite of the passTypeId and seralNumber to index the pass. If these are both the same, the pass is updated. So your second pass, with the same passTypeId and serialNumber is updating your first one - this is why you only see one pass in the wallet. Make the serial on the second pass different and your problem will be fixed. – PassKit Apr 22 '19 at 14:11
  • My app requirement has an event and an event has 2 or more types of pass (platinum, gold ) so how can I change my pass type id and serial number for 2nd pass because I generate 1 passtype ID for my application so is it require that different passtype ID for different passes? – SmarterSusheel Apr 22 '19 at 14:14
  • Serial number needs to be unique for each pass - just use a random generator, or use a different serial for platinum and gold. There’s no other way around it - it is used as an index and quite clearly explained in the documentation. – PassKit Apr 22 '19 at 14:16
  • But you told me in your answer is like "passes are uniquely indexed by certificate and serial number" so how can I change serial number because my serial number is uniquely identified with my passtype certificate. – SmarterSusheel Apr 22 '19 at 14:19
  • No - the index forms a composite key that can identify any individual pass bearing your passTypeId. Other passTypeId holders are free to set their own serials, which is why serial on it’s own can not be used as an index. Just change the serial of the second pass - that’s all you need to do. There is absolutely no way to have 2 passes with the same passTypeId and serialNumber in a single wallet. – PassKit Apr 22 '19 at 14:22
  • you are right, I have updated my pass ID and generated randomly and my issue is solved. – SmarterSusheel Apr 23 '19 at 04:52