【问题标题】:How to fix Application tried to present a nil modal view controller on target?如何修复应用程序试图在目标上呈现一个 nil 模态视图控制器?
【发布时间】:2017-01-25 08:51:14
【问题描述】:

我尝试在我的应用程序中实现 Apple Pay,但我收到一个错误,例如“应用程序试图在目标上呈现一个 nil 模态视图控制器” 在下面的 sn-p 中,谁能告诉我是不是错了。

PKPaymentAuthorizationViewController *vc = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:payment];
vc.delegate = self;
[self presentViewController:vc animated:YES completion:nil];

【问题讨论】:

    标签: ios ios7 applepay


    【解决方案1】:

    您的应用的 Apple Pay 权利可能设置不正确。

    我注意到当未设置权利时,canMakePayments 返回 YEScanMakePaymentsUsingNetworks: 返回 NO

    (我还注意到,当您在 PKPaymentRequest 上设置的商户 ID 与您的 Apple Pay 授权的商户 ID 不匹配时,它们都可以返回 YES。在这种情况下,您的 PKPaymentAuthorizationViewController 将是非零,但显示它会在控制台中记录一个神秘的错误)。

    因此,要验证是否为您的应用配置了 Apple Pay,请确保目标设置的“功能”部分中的“Apple Pay”为“开启”,并且它具有商家标识符(您需要 @987654321 @如果你还没有)。

    然后:

    • 如果使用直接的PassKit 集成方法,请确保将merchantIdentifier 属性设置为权利中匹配的商家标识符。

    请检查此代码:

    if ([PKPaymentAuthorizationViewController canMakePayments]) {
        NSLog(@"Can Make Payments");
        PKPaymentAuthorizationViewController *viewController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
        if (!viewController) { /* ... Handle error ... */ }
        viewController.delegate = self;
        [self presentViewController:viewController animated:YES completion:nil];
    }
    else {
        NSLog(@"Can't Make payments");
    }
    

    使用示例代码引用此网址:https://developer.apple.com/library/content/ApplePay_Guide/CreateRequest.html#//apple_ref/doc/uid/TP40014764-CH3-SW2

    【讨论】:

    • @bhardresh 它在模拟器中工作,但在设备中它崩溃了。
    • 我必须向哪个证书添加 uuid
    • 转到功能->Apple pay check all contains true or red display/
    【解决方案2】:

    // 一旦检查你的控制器是否正确初始化

         if (!viewController) { 
              [self presentViewController:vc animated:YES completion:nil];
         } else {
           // handle error , may be request is not proper to initializing the    PKPaymentAuthorizationViewController
      }
    

    【讨论】:

      【解决方案3】:

      实际上它可以在模拟器上运行,但当 Apple Pay 不支持在设备分配到的国家/地区时,它不能在真实设备上运行。请考虑一下。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-04
        • 1970-01-01
        • 2020-08-26
        • 2016-12-22
        • 2014-09-16
        相关资源
        最近更新 更多