Ios Can';无法从ApplePay PKPaymentAuthorizationViewController获取电子邮件

Ios Can';无法从ApplePay PKPaymentAuthorizationViewController获取电子邮件,ios,swift,applepay,Ios,Swift,Applepay,我正在使用ApplePay,需要电子邮件作为联系信息。当我试图收到电子邮件时,我收到的电子邮件结果是“发送”,我甚至不知道它来自哪里 我要求在请求中填写电子邮件字段,并填写电子邮件信息 request.requiredShippingAddressFields = PKAddressField.PostalAddress | PKAddressField.Email 代码如下: func paymentAuthorizationViewController(controller: PKPaym

我正在使用ApplePay,需要电子邮件作为联系信息。当我试图收到电子邮件时,我收到的电子邮件结果是“发送”,我甚至不知道它来自哪里

我要求在请求中填写电子邮件字段,并填写电子邮件信息

request.requiredShippingAddressFields = PKAddressField.PostalAddress | PKAddressField.Email
代码如下:

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"
     }
    ...
 }
这是收电子邮件的好地方吗?如果不是,正确的方法是什么


尝试获取电话号码(KabbersonPhoneProperty),结果也会打印为“Shipping”。

您的代码中有一个微妙的“输入错误:)
ab多值CopyLabelaIndex
复制条目的标签(即“装运”)。您需要使用
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!
  }
您的代码中有一个微妙的“输入错误:)
ab多值CopyLabelaIndex
复制条目的标签(即“装运”)。您需要使用
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!
  }
适用于iOS9及更新版本

let email = payment.shippingContact?.emailAddress
适用于iOS9及更新版本

let email = payment.shippingContact?.emailAddress

请将上述答案转换为目标C。请将上述答案转换为目标C。