收集物理地址和电话号码
了解如何在移动应用中收集地址和电话号码。
要收集完整的账单地址或收货地址,请使用 Address Element。
还可以使用 Address Element 执行以下作:
- 收集客户电话号码
- 使用自动完成功能(在 iOS 中默认启用)
- 通过传入收货地址在 Payment Element 中预填充账单信息
Stripe 将收集的地址信息和支付方式合在一起来创建 PaymentIntent。

设置地址自动完成建议
iOS 系统会默认启用自动完成功能。
配置 Address Element
可以使用显示默认值、设置允许的国家/地区、自定义外观等详细信息来配置 Address Element。有关配置选项的完整列表,请参阅 AddressViewController.Configuration。
let addressConfiguration = AddressViewController.Configuration( additionalFields: .init(phone: .required), allowedCountries: ["US", "CA", "GB"], title: "Shipping Address" )
检索地址详情
通过满足 AddressViewControllerDelegate
并使用 addressViewControllerDidFinish 关闭视图控制器来检索地址详细信息。地址的值是有效的地址或空。
extension MyViewController: AddressViewControllerDelegate { func addressViewControllerDidFinish(_ addressViewController: AddressViewController, with address: AddressViewController.AddressDetails?) { addressViewController.dismiss(animated: true) self.addressDetails = address } }
显示 Address Element
使用以上步骤中的地址配置和委托创建 AddressViewController。您可以将其显示在导航控制器中,也可以将其推送到导航控制器上。
self.addressViewController = AddressViewController(configuration: addressConfiguration, delegate: self) let navigationController = UINavigationController(rootViewController: addressViewController) present(navigationController, animated: true)