Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Apple Pay可以在模拟器上工作,但不能在设备上工作_Ios_Swift_Applepay - Fatal编程技术网

Ios Apple Pay可以在模拟器上工作,但不能在设备上工作

Ios Apple Pay可以在模拟器上工作,但不能在设备上工作,ios,swift,applepay,Ios,Swift,Applepay,我可以在模拟器上显示Apple Pay view控制器,但不能在设备上显示 添加权限并安装证书 class ViewController: UIViewController, PKPaymentAuthorizationViewControllerDelegate { var paymentRequest: PKPaymentRequest! override func viewDidLoad() { super.viewDidLoad() } func rydes(ship

我可以在模拟器上显示Apple Pay view控制器,但不能在设备上显示

添加权限并安装证书

class ViewController: UIViewController, PKPaymentAuthorizationViewControllerDelegate {

var paymentRequest: PKPaymentRequest! 

override func viewDidLoad() {
    super.viewDidLoad()

}


func rydes(shipping: Double) -> [PKPaymentSummaryItem] {

    let ryde = PKPaymentSummaryItem(label: "Your Fare", amount: 1.00)
    let discount = PKPaymentSummaryItem(label: "Discount", amount: -0.00)
    let shipping = PKPaymentSummaryItem(label: "Shipping", amount: NSDecimalNumber(string: "\(shipping)"))
    let subTotal = ryde.amount.adding(discount.amount)
    let total = PKPaymentSummaryItem(label: "rydes", amount: subTotal)

    return [ryde, discount, shipping, total]

} // rydes() func


    func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didSelect shippingMethod: PKShippingMethod, completion: @escaping (PKPaymentAuthorizationStatus, [PKPaymentSummaryItem]) -> Void) {

        completion(PKPaymentAuthorizationStatus.success, rydes(shipping: Double(shippingMethod.amount)))

    } // paymentAuthorizationViewController( didSelectShippingMethod )



    func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {

        completion(PKPaymentAuthorizationStatus.success)

    } // paymentAuthorizationViewController( didAuthorizePayment )



    func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {

        controller.dismiss(animated: true, completion: nil)

    } // paymentAuthorizationViewControllerDidFinish()


@IBAction func applePayPressed(_ sender: Any) {


    print("enable apple pay")

    // send user to Apple Pay to make payment

    let paymentNetworks = [PKPaymentNetwork.visa, .masterCard, .interac, .discover, .amex]
    let merchantId = "merchant.com.xxx"


    if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) {

        paymentRequest = PKPaymentRequest()
        paymentRequest.currencyCode = "CAD"
        paymentRequest.countryCode = "CA"
        paymentRequest.merchantIdentifier = merchantId
        paymentRequest.supportedNetworks = paymentNetworks
        paymentRequest.merchantCapabilities = .capability3DS
        paymentRequest.requiredShippingAddressFields = [.all]
        paymentRequest.paymentSummaryItems = self.rydes(shipping: 0.00)

        // . . .  shipping - not really needed

        let samedayShipping = PKShippingMethod(label: "Same Day", amount: 12.99)
        samedayShipping.detail = "Guaranteed same day delivery."
        samedayShipping.identifier = "sameday"

        let twodayShipping = PKShippingMethod(label: "Two Day", amount: 4.99)
        twodayShipping.detail = "Guaranteed within two days."
        twodayShipping.identifier = "twoday"

        let freeShipping = PKShippingMethod(label: "Same Day", amount: 0.00)
        freeShipping.detail = "Guaranteed same day."
        freeShipping.identifier = "freeShipping"

        paymentRequest.shippingMethods = [samedayShipping, twodayShipping, freeShipping]

        // . . .  shipping - not really needed

        let applePayVC = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest)
        applePayVC.delegate = self
        self.present(applePayVC, animated: true, completion: nil)

    }  else {

        print("Tell the user they need to set up Apple Pay!")
    }

} // applePayPressed func ACTION

}
上面的代码只返回这一行-告诉用户他们需要设置Apple Pay

我使用iPhone 6s作为设备,Apple Pay和Wallet通过有效的借记卡和信用卡启用。我来自加拿大,所以我在一个有效的地区

编辑代码


启用Apple Pay to我的应用程序时,我面临同样的问题。确保您在PKPayment中输入了所有有效的装运、服务和总付款值​总结​项目

总付款值也应大于0.0,以显示付款门通道视图。如果其中任何一个值为0.0,则不要将其添加为SummaryItem。

有效PKPaymentSummaryItem的代码:

{
// 12.75 subtotal
NSDecimalNumber *subtotalAmount = [NSDecimalNumber decimalNumberWithMantissa:1275
 exponent:-2 isNegative:NO];
self.subtotal = [PKPaymentSummaryItem summaryItemWithLabel:@"Subtotal" amount:subtotalAmount];

// 2.00 discount
NSDecimalNumber *discountAmount = [NSDecimalNumber decimalNumberWithMantissa:200 exponent:-2 isNegative:YES];
self.discount = [PKPaymentSummaryItem summaryItemWithLabel:@"Discount" amount:discountAmount];

// 12.75 - 2.00 = 10.75 grand total
NSDecimalNumber *totalAmount = [NSDecimalNumber zero];
totalAmount = [totalAmount decimalNumberByAdding:subtotalAmount];
totalAmount = [totalAmount decimalNumberByAdding:discountAmount];
self.total = [PKPaymentSummaryItem summaryItemWithLabel:@"My Company Name" amount:totalAmount];
self.summaryItems = @[self.subtotal, self.discount, self.total];
request.paymentSummaryItems = self.summaryItems;
}
这将尝试解决您的上述问题

编辑: 只需删除下面的代码并再次检查,或者设置检查条件,如果折扣或发货的值大于0.0,则您可以将发货和折扣作为摘要项目发送:

    let ryde = PKPaymentSummaryItem(label: "Your Fare", amount: 1.00)
//change some value here:
    let discount = PKPaymentSummaryItem(label: "Discount", amount: -0.00)
    let shipping = PKPaymentSummaryItem(label: "Shipping", amount: NSDecimalNumber(string: "\(shipping)"))
Make sure your subtotal or total is greater that 0.0.
    let subTotal = ryde.amount.adding(discount.amount)
    let total = PKPaymentSummaryItem(label: "rydes", amount: subTotal)

怎么可能会受到家长控制呢?我查过了,所有的限制都取消了!您在以下位置缺少报价:
let merchantId=merchant.com.xxx“@Brandon我只是把它放在那里,以免显示我的商户ID。-谢谢更新:-)我不太了解Objective-C,你能把它放在Swift 3中吗?不走运:/。我删除了所有的折扣和运输,因为我没有使用它们,仍然没有运气。在编辑中修改了代码。我发现了问题,除了运费和折扣外,我决定将我的visa卡和Interac借记卡一起添加到我的钱包中,并且成功了。当我看这些卡时,它说借记卡不能用于应用内支付。知道为什么吗?嗨,利兹,你解决问题了吗?我也有同样的错误?我使用swift实现了带条纹的apple pay。我运行这个程序,它在模拟器中运行得很好,但在真正的iphone设备中不工作?在真正的设备中,它不显示工资单。为什么?你知道原因吗?请帮帮我。要测试apple pay in real device,我们可以在钱包中添加测试卡吗?那么只有在real device中才能工作
    let ryde = PKPaymentSummaryItem(label: "Your Fare", amount: 1.00)
//change some value here:
    let discount = PKPaymentSummaryItem(label: "Discount", amount: -0.00)
    let shipping = PKPaymentSummaryItem(label: "Shipping", amount: NSDecimalNumber(string: "\(shipping)"))
Make sure your subtotal or total is greater that 0.0.
    let subTotal = ryde.amount.adding(discount.amount)
    let total = PKPaymentSummaryItem(label: "rydes", amount: subTotal)