[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];
}