Loading Apple Pay Shipping Address No Street

北城以北 提交于 2019-11-29 23:31:10

问题


I'm trying to get a shipping address extracted from the ABRecordRef provided by Apple. I have the following but my street is always returning as 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);
}

What am I doing wrong?

Even when debugging with the following:

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                  didSelectShippingAddress:(ABRecordRef)customShippingAddress
                                completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray *methods, NSArray *items))completion
{
    NSLog(@"%@", ABRecordCopyValue(customShippingAddress, kABPersonAddressProperty);
    completion(PKPaymentAuthorizationStatusSuccess, ..., ...);
}

I get this with no street:

ABMultiValueRef 0x17227fbc0 with 1 value(s)
    0: Shipping (0x17227fa00) - {
    City = "Marina del Rey";
    Country = "United States";
    State = California;
    ZIP = 90292;
} (0x172447440)

Edit:

I'm also experiencing issues with accessing names and phone attributes:

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

This is how the PKPaymentRequest is being created:

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]];

回答1:


Turns out Apple's docs on this weren't that great but the issue is that in the delegate callback for paymentAuthorizationViewController:didSelectShippingAddress:completion: a partial address is always returned. The fix is to also set it in the callback from:

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                       didAuthorizePayment:(PKPayment *)payment
                                completion:(void (^)(PKPaymentAuthorizationStatus))completion
{
    // Use this instead.
    [payment shippingAddress];
}

I also removed a call to setting the required billing addresses (maybe a separate bug).



来源:https://stackoverflow.com/questions/26518767/loading-apple-pay-shipping-address-no-street

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!