【问题标题】:Apple Pay detect Wallet has no credit cardsApple Pay 检测 Wallet 没有信用卡
【发布时间】:2015-11-20 21:23:40
【问题描述】:

我正在尝试为我的应用实施 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 present as nil view controller

Apple pay PKPaymentauthorizationViewController always returning nil when loaded with Payment request

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

【问题讨论】:

标签: ios objective-c applepay


【解决方案1】:

我按照@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;
}

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

谢谢!

【讨论】:

  • 据我所知,如果用户不返回您的应用程序,就无法让它们恢复原状。不过,我希望人们能自己想出这么多:)
猜你喜欢
  • 1970-01-01
  • 2019-03-27
  • 1970-01-01
  • 2016-01-01
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-15
相关资源
最近更新 更多