我正在尝试在我的iOS Xamarin应用程序上实现设置Apple Pay按钮。我已经为它添加了按钮和单击处理程序。然后使用PKPassLibrary.OpenPaymentSetup()打开Wallet。然后,如果用户成功地将卡添加到钱包中,我需要通过更改“设置ApplePay按钮”为“用Apple Pay支付”来处理此事件。但我找不到工作的任何事件处理程序或类似的东西。
我试过的:
private PKPassLibrary _library;
private NSObject _walletNotificationSubscription;
private void OnSetuApplePayClicked(object button, EventArgs args)
{
_library = new PKPassLibrary();
_library.OpenPaymentSetup();
_walletNotificationSubscription = PKPassLibrary.Notifications.ObserveDidChange(_library, HandleEventHandler);
}
void HandleEventHandler(object sender, NSNotificationEventArgs e)
{
_walletNotificationSubscription.Dispose();
ViewModel.UpdateApplePay();
SetButtonVisibility();
}
但它不起作用。
附注:我想我可能观察到了不正确的事件。
请尝试使用以下代码:
if(PKPaymentAuthorizationViewController.CanMakePayments)
{
//the device supports Apple Pay
//check whether the user can make a payment with a bank card ,such as Amex ,MasterCard,Visa,ChinaUnion and so on
NSString[] paymentString = { PKPaymentNetwork.Amex, PKPaymentNetwork.ChinaUnionPay, PKPaymentNetwork.MasterCard, PKPaymentNetwork.Visa };
if(PKPaymentAuthorizationViewController.CanMakePaymentsUsingNetworks(paymentString))
{
//user has added bank card ,do something you want
}
else
{
//user has not added bank card
}
}
else
{
//the device doesn't support Apple Pay
}
还有一些其他的付款方式,你可以把它们签入
公共静态类PKPaymentNetwork