【问题标题】:Loading Apple Pay Shipping Address No Street正在加载 Apple Pay 送货地址 No Street
【发布时间】:2014-10-22 23:17:31
【问题描述】:

我正在尝试从 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);
}

我做错了什么?

即使在使用以下调试时:

- (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

这是创建 PKPaymentRequest 的方式:

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

【问题讨论】:

    标签: ios objective-c applepay


    【解决方案1】:

    事实证明,Apple 在这方面的文档不是很好,但问题是在 paymentAuthorizationViewController:didSelectShippingAddress:completion: 的委托回调中,总是返回了部分地址。修复方法是在回调中设置它:

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

    我还删除了设置所需帐单地址的调用(可能是一个单独的错误)。

    【讨论】:

    • 正确。出于安全目的,仅返回部分地址,这足以计算运费以在用户验证付款之前显示。一旦通过身份验证,用户基本上已批准访问他们提供的完整地址,否则无法发货。
    • 请记住,加拿大和英国的邮政编码不会作为完整的邮政编码(仅部分)返回,这可能会使计算这些国家/地区的某些承运人的运费变得更加困难。跨度>
    猜你喜欢
    • 2016-04-04
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多