适用于 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/