4

Sorry if this sounds dumb, complete swift noob here,

I'm trying to create the "Add to Apple Wallet" button. But I can't figure out how. I've tried the code snippet here, but nothing showed up on my screen in the simulator. My current code:

import UIKit
import PassKit


class ViewController: UIViewController {

    @IBOutlet weak var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        addWalletButton()

    }

    private func addWalletButton() {
        let passButton =  PKAddPassButton(addPassButtonStyle: PKAddPassButtonStyle.black)
        passButton.center = view.center
        view.addSubview(passButton)
    }

}

Any suggestions? Thanks.

asportnoy
  • 2,218
  • 2
  • 17
  • 31

1 Answers1

4

Looks like your button has no bounds.

Try:

let passButton = PKAddPassButton(addPassButtonStyle: PKAddPassButtonStyle.black)
passButton.frame = CGRect(x:  (UIScreen.main.bounds.width-280)/2, y: 150, width: 280, height: 60)
passButton.addTarget(self, action: #selector(passButtonAction), for: .touchUpInside)
view.addSubview(passButton)

Adjust the size and position to suit your app. And don't forget to add an action so it does something when tapped.

PassKit
  • 12,231
  • 5
  • 57
  • 75
  • Remove the addTarget line if you haven’t set an action function yet, then replace the code in your addWalletButton function. – PassKit May 20 '19 at 05:27