加载Apple Pay送货地址No Street
我正在尝试从Apple提供的ABRecordRef
提取送货地址。 我有以下但我的街道总是返回nil
:
ABMultiValueRef addresses = ABRecordCopyValue(abRecordRef, kABPersonAddressProperty); for (CFIndex index = 0; index < ABMultiValueGetCount(addresses); index++) { CFDictionaryRef properties = ABMultiValueCopyValueAtIndex(addresses, index); NSString *street = [(__bridge NSString *)(CFDictionaryGetValue(properties, kABPersonAddressStreetKey)) copy]; NSLog(@"street: %@", street); }
我究竟做错了什么?
即使在用以下方式进行debugging时:
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingAddress:(ABRecordRef)customShippingAddress completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray *methods, NSArray *items))completion { NSLog(@"%@", ABRecordCopyValue(customShippingAddress, kABPersonAddressProperty); completion(PKPaymentAuthorizationStatusSuccess, ..., ...); }
我得到这个没有街道:
ABMultiValueRef 0x17227fbc0 with 1 value(s) 0: Shipping (0x17227fa00) - { City = "Marina del Rey"; Country = "United States"; State = California; ZIP = 90292; } (0x172447440)
编辑 :
我也遇到访问名称和电话属性的问题:
NSString *name = (__bridge_transfer NSString *)(ABRecordCopyCompositeName(abRecordRef)); NSString *fname = (__bridge_transfer NSString *)ABRecordCopyValue(abRecordRef, kABPersonFirstNameProperty); NSString *lname = (__bridge_transfer NSString *)ABRecordCopyValue(abRecordRef, kABPersonFirstNameProperty); if (!name && fname && lname) name = [NSString stringWithFormat:@"%@ %@", fname, lname]; NSLog(@"name: %@", name); // nil
这是如何创buildPKPaymentRequest:
PKPaymentRequest *pr = [[PKPaymentRequest alloc] init]; [pr setMerchantIdentifier:@"********"]; [pr setCountryCode:@"US"]; [pr setCurrencyCode:@"USD"]; [pr setMerchantCapabilities:PKMerchantCapability3DS]; [pr setSupportedNetworks:@[PKPaymentNetworkAmex, PKPaymentNetworkVisa, PKPaymentNetworkMasterCard]]; [pr setPaymentSummaryItems:[self paymentSummaryItems]]; [pr setRequiredBillingAddressFields:PKAddressFieldAll]; [pr setRequiredShippingAddressFields:PKAddressFieldAll]; [pr setShippingMethods:[self supportedShippingMethods]];
原来,苹果公司的文档并不是那么好,但问题是在paymentAuthorizationViewController:didSelectShippingAddress:completion:
callbackpaymentAuthorizationViewController:didSelectShippingAddress:completion:
总是返回一个部分地址。 解决方法是也将其设置在以下callback中:
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion { // Use this instead. [payment shippingAddress]; }
我也删除了设置所需的帐单地址(也许是一个单独的错误)的电话。