gpt4 book ai didi

iphone - iOS 上 PayPal 的 MPL 库的初始化实际上是一个阻塞过程吗?

转载 作者:太空宇宙 更新时间:2023-11-03 16:36:30 24 4
gpt4 key购买 nike

适用于 iOS 的 PayPal 移动支付库的文档 here指出您有两个选项来初始化库。 选项 1 是:

"Initialize the PayPal object on the main thread, when you need it. Initialize the library each time before you call the getPayButtonWithTarget method. This implementation is simple because it uses a single-threaded programming model. The initializeWithAppID call is blocking, so your application waits for the initialization to complete.
To use this method, you can use one line of code: [PayPal initializeWithAppID:appID];"

但是,每当我在主线程上调用此函数时,我都会返回 STATUS_INPROGRESS。我别无选择,只能手动休眠,直到状态变为 STATUS_COMPLETED_SUCCESS。

什么给了?

最佳答案

你可以打电话
[PayPal initializeWithAppID:appID]ViewController 的主线程中,但您必须等待2-3 秒用于Paypal 在点击按钮进行支付之前初始化信息。 (如果你使用这个例子
[[PayPal getPayPalInst] getPayButtonWithTarget:self...]; 您将看到按钮最初被禁用,仅在 1-2 秒后启用(变为黄色)。如果你想调用
- (IBAction)simplePayment{} 来自主线程,您必须创建后台线程。类似主题:iPhone PayPal init failed

-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[PayPal initializeWithAppID:@"APP-80W284485P519543T" forEnvironment:ENV_SANDBOX];
[NSThread detachNewThreadSelector:@selector(checkInitStatusAndPay) toTarget:self withObject:nil];
}

-(void) checkInitStatusAndPay {


while (TRUE) {
PayPalInitializationStatus status = [PayPal initializationStatus];
NSLog(@"status %u", status);
if(status == STATUS_COMPLETED_SUCCESS) {

[self performSelectorOnMainThread:@selector(simplePayment:) withObject:nil waitUntilDone:NO];
break;
}
[NSThread sleepForTimeInterval:2];
}
}

- (IBAction)simplePayment:(id)sender {

....
[[PayPal getPayPalInst] checkoutWithPayment:payment];
}

关于iphone - iOS 上 PayPal 的 MPL 库的初始化实际上是一个阻塞过程吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12563290/

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