1

How can I add an Apple Wallet pass with a custom username and contents of a QR code? If possible can they be downloaded from a server?

I have tried altering existing passes but there is no capability to do that in Xamarin.

user8859191
  • 50
  • 3
  • 8
  • you could look at [PassKit](https://learn.microsoft.com/en-us/xamarin/ios/platform/passkit?tabs=windows),maybe it will help you – Leo Zhu Oct 08 '19 at 07:44

1 Answers1

1

So the beauty of using Xamarin is that you have access to all the native iOS APIs that are available to Swift developers, so you can do everything in C# that you can with Swift without the need for custom binding.

So anything that you can do using Swift on XCode, you can do that in an identical way using C#. So in order to implement the Apple Wallet passes, you have to go through the same procedures. The procedure is slightly long since this is for Card Issuers only and you need a special entitlement issued by Apple:

Your app must include this entitlement before you can use this class. For more information on requesting this entitlement, see the Card Issuers section at developer.apple.com/apple-pay/.

Also, from here:

PKAddPaymentPassViewController requires the com.apple.developer.payment-pass-provisioning entitlement key for your app. The bad news is that not anyone can submit apps with this entitlement as it requires special permission from Apple, which I believe is reserved for card issuers like banks and similar. If you believe that you qualify you need to contact Apple directly at apple-pay-inquiries@apple.com

Once you get that done, you need to implement the delegate methods, and initialize it with a configuration as you can see in the code/picture below (Converted from Swift):

using System;
using CoreGraphics;
using Foundation;
using ObjCRuntime;
using PassKit;
using UIKit;

namespace BlankNativeApp.iOS
{
    public class PKViewController : UIViewController, IPKAddPaymentPassViewControllerDelegate
    {
        public void DidFinishAddingPaymentPass(PKAddPaymentPassViewController controller, PKPaymentPass pass, NSError error)
        {
            // Perform Post Addition Functionality
        }

        public void GenerateRequestWithCertificateChain(PKAddPaymentPassViewController controller, NSData[] certificates, NSData nonce, NSData nonceSignature, [BlockProxy(typeof(NIDActionArity1V173))] Action<PKAddPaymentPassRequest> handler)
        {
            // Do work that needs to be done with certifications
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (!PKAddPaymentPassViewController.CanAddPaymentPass)
            {
                // use other payment method / alert user
            }
            var config = new PKAddPaymentPassRequestConfiguration(PKEncryptionScheme.Ecc_V2);
            var addPaymentPassVC = new PKAddPaymentPassViewController(config, this);
            View.BackgroundColor = UIColor.White;
            Title = "My Custom View Controller";

            var btn = UIButton.FromType(UIButtonType.System);
            btn.Frame = new CGRect(20, 200, 280, 44);
            btn.SetTitle("Click Me", UIControlState.Normal);
            btn.TouchUpInside += (sender, e) => {
                //this.ShowViewController(addPaymentPassVC, (Foundation.NSObject)sender); This line will also work
                this.PresentViewControllerAsync(addPaymentPassVC, true);
            };
            View.AddSubview(btn);
        }
    }
}

Implementation example for Passkit

Saamer
  • 4,687
  • 1
  • 13
  • 55