5

我正在尝试为我的应用实施 Apple Pay。我有 PKPaymentAuthorizationViewController 试图加载 Apple Pay 视图。如果我的钱包中没有任何卡,则构造函数将这个视图控制器返回为 Nil。所以,我决定引导用户完成他们输入卡片信息的过程。我能够使用

PKPassLibrary* lib = [[PKPassLibrary alloc] init];
[lib openPaymentSetup];

这是我初始化 PKPaymentAuthorizationViewController 的部分。这会在模拟器上返回一个有效的对象来显示视图。但是在没有配置信用卡的真实设备上返回 nil 并运行时异常。下面是初始化代码:

if ([PKPaymentAuthorizationViewController canMakePayments]) {
// init arr
[arr addObject:total];
request.paymentSummaryItems = arr;
PKPaymentAuthorizationViewController *paymentPane = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentPane.delegate = self;
[self presentViewController:paymentPane animated:TRUE completion:nil];
}

这里的数组是 PKPaymentSummaryItem 的有效 NSArray,这就是为什么在模拟器上成功工作的原因。

每次我看到钱包里没有信用卡的用户时,我都需要调用上面的 openPaymentSetup 方法。有没有办法检测到呢?

目前我正在使用

if ( [PKPassLibrary isPassLibraryAvailable] ) {
    PKPassLibrary* lib = [[PKPassLibrary alloc] init];
    if  ([lib passesOfType:PKPassTypePayment].count == 0 ) {
        [lib openPaymentSetup];
   }
}

但这不起作用,因为我正在查看钱包中的通行证计数。这可能像航空公司的登机牌,或 eventbrite 通行证等。

看着: PKPaymentAuthorizationViewController 呈现为 nil 视图控制器

Apple pay PKPaymentauthorizationViewController 在加载支付请求时总是返回 nil

https://developer.apple.com/library/ios/documentation/PassKit/Reference/PKPaymentAuthorizationViewController_Ref/

4

1 回答 1

5

我按照@maddy 的建议做了,它确实有效。不幸的是,苹果关于它的文档非常有限。谢谢麦迪。

这是我的代码

-(BOOL) openAddCardForPaymentUIIfNeeded
{
    if ( [PKPassLibrary isPassLibraryAvailable] )
    {
        if ( ![PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:[NSArray arrayWithObjects: PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa, nil]] )
        {
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Add a Credit Card to Wallet" message:@"Would you like to add a credit card to your wallet now?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
            [alert show];
            return true;

        }
    }
    return false;
}

现在我正在指导用户在钱包应用程序中添加卡片向导。用户在钱包中添加完卡后,有什么方法可以让用户返回应用程序?

谢谢!

于 2015-11-24T17:54:51.190 回答