2

PKPaymentRequest.billingAddress / shippingAddressここに記載されているように、ファイルにあるアドレスを入力しようとしています。

https://developer.apple.com/library/ios/documentation/PassKit/Reference/PKPaymentRequest_Ref/#//apple_ref/occ/instp/PKPaymentRequest/billingAddress

これには、ゼロから作成する必要がありますABRecordRef。以下は私の最善の試みですが、有用なエラー メッセージが表示されずにアプリがクラッシュします。

var request = PKPaymentRequest();

var person: ABRecordRef = ABPersonCreate().takeRetainedValue()
ABRecordSetValue(person, kABPersonFirstNameProperty, "John", nil)
ABRecordSetValue(person, kABPersonLastNameProperty, "Doe", nil)

var multiValue : ABMutableMultiValue = ABMultiValueCreateMutable(ABPropertyType(kABPersonAddressProperty)).takeRetainedValue()
ABMultiValueAddValueAndLabel(multiValue, "123 Test Street", kABPersonAddressStreetKey, nil)
ABMultiValueAddValueAndLabel(multiValue, "Mountain View", kABPersonAddressCityKey, nil)
ABMultiValueAddValueAndLabel(multiValue, "CA", kABPersonAddressStateKey, nil)
ABMultiValueAddValueAndLabel(multiValue, "94040", kABPersonAddressZIPKey, nil)

ABRecordSetValue(person, kABPersonAddressProperty, multiValue, nil)

request.shippingAddress = person
request.billingAddress = person
4

1 に答える 1

5

さらに数時間の献身の末、これを理解することができました。以下を参照してください。

//Initialize new PassKit Payment Request
var request = PKPaymentRequest();

//Initialize ABRecord to pre-populate AP payment sheet
var record: ABRecordRef = ABPersonCreate().takeRetainedValue()

//Pre-populate first & last name
ABRecordSetValue(record, kABPersonFirstNameProperty, "John", nil)
ABRecordSetValue(record, kABPersonLastNameProperty, "Doe", nil)

//Pre-populate phone
var phone: ABMultiValueRef = ABMultiValueCreateMutable(ABPropertyType(kABMultiStringPropertyType)).takeRetainedValue()
ABMultiValueAddValueAndLabel(phone, "(555)123-4567", kABHomeLabel, nil)
ABRecordSetValue(record, kABPersonPhoneProperty, phone, nil)

//Pre-populate email
var email: ABMultiValueRef = ABMultiValueCreateMutable(ABPropertyType(kABMultiStringPropertyType)).takeRetainedValue()
ABMultiValueAddValueAndLabel(email, "john.doe@test.com", kABHomeLabel, nil)
ABRecordSetValue(record, kABPersonEmailProperty, email, nil)

//Pre-populate address
var address: ABMultiValueRef = ABMultiValueCreateMutable(ABPropertyType(kABMultiDictionaryPropertyType)).takeRetainedValue()
var addressDictionary : [String:String] = [kABPersonAddressStreetKey as String: "123 Test Street", kABPersonAddressCityKey as String: "Palo Alto", kABPersonAddressStateKey as String: "CA", kABPersonAddressZIPKey as String: "94301", kABPersonAddressCountryKey as String: "United States"]
ABMultiValueAddValueAndLabel(address, addressDictionary, kABOtherLabel, nil)
ABRecordSetValue(record, kABPersonAddressProperty, address, nil)

//Assign ABRecord to PKPaymentRequest
request.shippingAddress = record
request.billingAddress = record
于 2015-05-08T07:10:50.437 に答える