我正在研究一个库,该库创建一个提供本机套用支付功能的React-Native模块。实际呈现Apple Pay View控制器的控制器:
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *rootViewController = RCTPresentedViewController();
[rootViewController presentViewController:self.viewController animated:YES completion:nil];
callback(@[[NSNull null]]);
});
还将自己附加到该委托人PKPaymentAuthorizationViewControllerDelegate
上,并且像文档中所解释的那样,它提供了didSelectShippingContact
启动时的功能:
// Shipping Contact
- (void) paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
didSelectShippingContact:(PKContact *)contact
completion:(nonnull void (^)(PKPaymentAuthorizationStatus, NSArray<PKShippingMethod *> * _Nonnull, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
{
self.shippingContactCompletion = completion;
NSLog(@"testis%@", contact);
CNPostalAddress *postalAddress = contact.postalAddress;
// street, subAdministrativeArea, and subLocality are supressed for privacy
[self.bridge.eventDispatcher sendDeviceEventWithName:@"NativePayments:onshippingaddresschange"
body:@{
@"recipient": [NSNull null],
@"organization": [NSNull null],
@"addressLine": [NSNull null],
@"city": postalAddress.city,
@"region": postalAddress.state,
@"country": [postalAddress.ISOCountryCode uppercaseString],
@"postalCode": postalAddress.postalCode,
@"phone": [NSNull null],
@"languageCode": [NSNull null],
@"sortingCode": [NSNull null],
@"dependentLocality": [NSNull null]
}];
}
苹果支付视图还可以处理运输信息之外的联系信息,但是我不确定如何将委托附加到该信息上,这样我就可以获取已存储/更新/选择/删除的联系信息。我一直在寻找一种类似于didSelectShippingContact => completion
的{{1}}的方式,但是我很快就迷路了。