Beeblex の新しい In App Purchase 検証をアプリに追加しようとしていますが、ブロック内から戻り値を渡すのに苦労しています。
これが私が今持っているコードです。ご覧のとおり、BOOL値を設定し、検証ブロック内でBOOLを設定して最後に返します。ただし、最後の return はブロックが終了する前に呼び出されるため、必要なのはブロック内から BOOL を返すことですか?
- (BOOL)verifyTransaction:(SKPaymentTransaction *)transaction
{
if (![BBXIAPTransaction canValidateTransactions]) {
return YES; // There is no connectivity to reach the server
}
BOOL __block toReturn = YES;
BBXIAPTransaction *bbxTransaction = [[BBXIAPTransaction alloc] initWithTransaction:transaction];
bbxTransaction.useSandbox = YES;
[bbxTransaction validateWithCompletionBlock:^(NSError *error) {
if (bbxTransaction.transactionVerified) {
if (bbxTransaction.transactionIsDuplicate) {
// The transaction is valid, but duplicate - it has already been sent to Beeblex in the past.
NSLog(@"Transaction is a duplicate!");
[FlurryAnalytics logEvent:@"Transaction duplicate!"];
toReturn = NO;
} else {
// The transaction has been successfully validated and is unique
NSLog(@"Transaction valid data:%@",bbxTransaction.validatedTransactionData);
[FlurryAnalytics logEvent:@"Transaction verified"];
toReturn = YES;
}
} else {
// Check whether this is a validation error, or if something went wrong with Beeblex
if (bbxTransaction.hasConfigurationError || bbxTransaction.hasServerError || bbxTransaction.hasClientError) {
// The error was not caused by a problem with the data, but is most likely due to some transient networking issues
NSLog(@"Transaction error caused by network, not data");
[FlurryAnalytics logEvent:@"Transaction network error"];
toReturn = YES;
} else {
// The transaction supplied to the validation service was not valid according to Apple
NSLog(@"Transaction not valid according to Apple");
[FlurryAnalytics logEvent:@"Transaction invalid!!"];
toReturn = NO;
}
}
}];
NSLog(@"toReturn: %@",toReturn ? @"Yes" : @"No");
return toReturn;
}
単純にreturn = NO;
ブロック内に配置すると、互換性のないブロック ポインター型のコンパイラ警告が表示され、制御が非 void ブロックの末尾に到達する可能性があります。