我正在尝试在我的 iOS Xamarin 应用程序上实现 SetUp Apple Pay 按钮。我已经为它添加了按钮和点击处理程序。然后我使用 PKPassLibrary.OpenPaymentSetup() 打开电子钱包。然后,如果用户已成功将卡添加到钱包中,我需要通过将“设置 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();
}
但它不起作用。
P.S.:我想我可能观察到了不正确的事件。
最佳答案
尝试使用以下代码:
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
}
还有一些其他的支付方式,你可以去看看
公共(public)静态类 PKPaymentNetwork
关于ios - 处理添加到钱包 Apple Pay 的信用卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52150168/