gpt4 book ai didi

ios - 正在加载 Apple Pay 送货地址 No Street

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:05 26 4
gpt4 key购买 nike

我正在尝试获取从 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]];

最佳答案

原来 Apple 的文档并不是那么好,但问题是在 paymentAuthorizationViewController:didSelectShippingAddress:completion: 的委托(delegate)回调中,部分地址总是返回.解决方法是在回调中也设置它:

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

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

关于ios - 正在加载 Apple Pay 送货地址 No Street,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26518767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com