Xamarin 中的 watchOS 上的 Apple PayApple Pay on watchOS in Xamarin

Apple 在 watchOS 3 中对 Apple Pay 进行了几项增强,增加了对应用中付款的支持。Apple has made several enhancements to Apple Pay in watchOS 3 that adds support for In-App Payments. 这样,用户就可以安全地提供支付和联系信息,以便直接从 Apple Watch 为实际货物和服务付费。This allows the user to securely provide payment and contact information to pay for physical goods and services directly from the Apple Watch.

关于 Apple Pay 增强功能About Apple Pay Enhancements

如上所述,Apple 已对 watchOS 3 中的 Apple Pay 进行了几项增强,使你可以通过安全的支付和联系信息直接从 Apple Watch 为物理商品和服务付费。As Stated above, Apple has made several enhancements to Apple Pay in watchOS 3 that allow for secure payment and contact information to pay for physical goods and services directly from the Apple Watch. 这些增强功能由对 PassKit 框架的修改提供。These enhancements are provided by modifications to the PassKit framework.

使用 iOS 10 和 watchOS 3,添加了几个新的 Api,它们适用于 iOS 和 watchOS 以支持动态支付网络和新的沙箱测试环境。With iOS 10 and watchOS 3, several new APIs have been added that work with both iOS and watchOS to support dynamic payment networks and a new sandbox test environment.

PassKit 框架增强功能PassKit Framework Enhancements

在 iOS 10 中,已将 PassKit 框架扩展为支持 UIKit 之外的 Apple Pay,并允许卡颁发商在其应用中提供其卡。In iOS 10, the PassKit framework has been expanded to support Apple Pay outside of UIKit and to allow card issuers to present their cards from within their apps.

UIKit 之外的支持 Apple PaySupporting Apple Pay Outside of UIKit

通过使用PKPaymentAuthorizationControllerPKPaymentAuthorixationControllerDelegate,应用可以支持PKPaymentAuthorizationViewController提供的同一功能,而无需使用 UIKit。By using PKPaymentAuthorizationController and PKPaymentAuthorixationControllerDelegate, an app can support the same functionality provided by PKPaymentAuthorizationViewController without using UIKit. 尽管此新 API 是支持 Apple Watch 上的 Apple Pay (也在特定意向中),但在其他情况下(如现有应用)是可选的。While this new API is required for supporting Apple Pay on the Apple Watch (and in specific Intents as well), it is optional in other situations (such as existing apps). 但是,Apple 建议尽快迁移到新的 API,以便在所有开发人员的应用程序中提供广泛的 Apple Pay 支持,只需要一个基本代码。However, Apple suggests moving to the new API as soon as possible to provide broad Apple Pay support throughout all of the developer's apps with a single code base. 有关意向和 Siri 集成的详细信息,请参阅SiriKit 文档简介For more information about Intents and Siri integration, please see our Introduction to SiriKit documentation.

在应用内展示颁发者卡Presenting Issuer Cards from within Apps

使用 iOS 10 和 watchOS 3,PassKit 框架中已添加了新功能,使卡颁发商可以在自己的应用中提供其支付卡。With iOS 10 and watchOS 3, new features have been added to the PassKit framework that allow card issuers to present their payment cards from within their own apps. 开发人员可以将 PKPaymentButtonTypeInStore UIButton 添加到应用程序的用户界面,该界面将显示卡片 Apple Pay 按钮。The developer can add a PKPaymentButtonTypeInStore UIButton to the app's user interface that will display an Apple Pay button for a card.

PKPassLibrary类的 PresentPaymentPass 方法还可用于以编程方式显示卡。The PresentPaymentPass method of the PKPassLibrary class can also be used to programmatically display the card.

新的付款网络支持New Payment Network Support

IOS 10 和 watchOS 3 的新增功能,应用程序可在无需修改、重新编译应用程序并将其重新提交到应用商店时自动支持新的付款网络。New to iOS 10 and watchOS 3, an app can automatically support a new payment network when it becomes available without the developer having to modify, recompile the app and resubmit it to the App Store.

使用 PKPaymentNetwork 类的新的AvailableNetworks方法,应用程序可以发现运行时用户设备上的可用网络。The new AvailableNetworks method of the PKPaymentNetwork class allows an app to discover the networks available on the user's device at runtime. 此外, SupportedNetworks属性已展开,以将付款提供程序的名称作为参数。Additionally, the SupportedNetworks property has been expanded to take the payment provider's name as an argument. 使用这些方法,应用程序可以自动支持支付提供商支持的任何网络。Using these methods, an app can automatically support any network that the payment provider supports.

有关详细信息,请参阅我们的Apple Pay 配置和 Apple Apple Pay 指南For more information, please see our Apple Pay Configuration and Apple's Apple Pay Guide.

新测试环境New Testing Environment

使用 iOS 10 和 watchOS 3,Apple 引入了新的测试环境,使开发人员能够直接在 iOS 设备上预配测试付款卡。With iOS 10 and watchOS 3, Apple introduced a new testing environment that allows the developer to provision test payment cards directly on an iOS device. 然后,这个新的测试环境会将加密的测试付款数据返回到应用程序。This new testing environment then returns encrypted test payment data to the app.

若要启用新的测试环境,请执行以下操作:To enable the new testing environment, do the following:

  1. 在 iTunes Connect 中创建新的测试 iCloud 帐户。Create a new testing iCloud Account in iTunes Connect.
  2. 用新的测试帐户登录到 iOS 设备。Log into the iOS device with the new testing account.
  3. 设置要在其中测试应用程序的所需区域。Set the desired region to test the app in.
  4. 使用 " Apple Pay 指南" 中的测试支付卡之一来支付。Use one of the test payment cards from the Apple Pay Guide to make payments.

备注

通过切换 iCloud 帐户,该设备将自动切换到新的测试环境。By switching iCloud Accounts, the device will automatically switch to the new testing environment. 但是,在提交给 iTunes 应用商店之前,Apple 仍要求在生产环境中使用真实卡测试该应用。However, Apple still requires the app to be tested with real cards in a production environment before submission to the iTunes App Store.

总结Summary

本文介绍了 Apple 在 watchOS 3 中 Apple Pay 的增强功能,以及如何在 Xamarin 中实现这些功能。This article has covered the enhancements Apple has made to Apple Pay in watchOS 3 and how to implement them in Xamarin.iOS.