1

I am using ApplePay and requiring email as contact information. When I am trying to get email, the email result I get is "Shipping" which I don't even know where it comes from.

I have required email field in the request, and filled in email information.

request.requiredShippingAddressFields = PKAddressField.PostalAddress | PKAddressField.Email

Here is the code:

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

    let address: ABRecord! = payment.shippingAddress

    let emails: ABMultiValueRef = ABRecordCopyValue(address, kABPersonEmailProperty).takeRetainedValue() as ABMultiValueRef
    if ABMultiValueGetCount(emails) > 0 {
        let email = ABMultiValueCopyLabelAtIndex(emails, 0).takeRetainedValue()
        NSLog(email)  //Here prints "Shipping"
     }
    ...
 }

Is this the right place to get email? If not, what is the correct approach?


Trying to get phone number (kABPersonPhoneProperty), the result printed as "Shipping" as well.

4

2 回答 2

2

您的代码中有一个微妙的“错字”:)。ABMultiValueCopyLabelAtIndex复制条目的标签(即“运输”)。您需要使用ABMultiValueCopyValueAtIndex.

  let emails: ABMultiValueRef = ABRecordCopyValue(address, kABPersonEmailProperty).takeRetainedValue() as ABMultiValueRef
  if ABMultiValueGetCount(emails) > 0 {
    let email = ABMultiValueCopyValueAtIndex(emails, 0).takeRetainedValue() as String
    NSLog(email)  //Here prints your email address!
  }
于 2015-02-06T23:12:48.673 回答
2

适用于 iOS9 及更高版本

let email = payment.shippingContact?.emailAddress
于 2016-04-07T16:58:27.857 回答