您可以
[PayPal initializeWithAppID:appID]
在 的主线程中调用ViewController
,但您需要等待 2-3 秒Paypal
才能初始化信息,然后单击按钮进行支付。(如果您使用示例
[[PayPal getPayPalInst] getPayButtonWithTarget:self...];
,您将看到按钮最初禁用,仅在 1-2 秒后启用(变为黄色)。如果您想
- (IBAction)simplePayment{}
从主线程调用,则必须创建后台线程。类似线程:iPhone PayPal初始化失败
-(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];
}