在尝试在iOS应用程序中设置Apple Pay时,我们遇到了API和预填充信息的问题.我们的用户流程允许用户在使用Apple Pay付款之前手动设置其地址,电子邮件和电话,因此如果他们决定这样做,我们想确保填写Apple Pay提示符.
根据development guide,这应该是在request.shippingContact中设置这些值一样简单.但是,当我们这样做时,值将被忽略.
有什么文件没有告诉我们吗?
PKContact *contact = [[PKContact alloc] init]; contact.emailAddress = @"john@appleseed.com"; contact.phoneNumber = [[CNPhoneNumber alloc] initWithStringValue:@"5555555"]; NSPersonNameComponents *name = [[NSPersonNameComponents alloc] init]; name.givenName = @"John"; name.familyName = @"Appleseed"; contact.name = name; request.billingContact = contact; request.shippingContact = contact; request.requiredBillingAddressFields = PKAddressFieldAll; request.requiredShippingAddressFields = PKAddressFieldEmail | PKAddressFieldPhone;
解决方法
如文档中所述,我们需要正确验证地址值.我们应该通过有效的邮政编码传递有效的地址,参见下面的代码.
PKContact *contact = [[PKContact alloc] init]; NSPersonNameComponents *name = [[NSPersonNameComponents alloc] init]; name.givenName = @"John"; name.familyName = @"Appleseed"; contact.name = name; CNMutablePostalAddress *address = [[CNMutablePostalAddress alloc] init]; address.street = @"1234 Laurel Street"; address.city = @"Atlanta"; address.state = @"GA"; address.postalCode = @"30303";
还要检查:
注意
地址信息可能来自iOS中广泛的来源.在使用之前始终验证信息.