1

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 ブロックの末尾に到達する可能性があります。

4

2 に答える 2

4

Beeblex 開発者はこちら。-validateWithCompletionBlock: 内のコードは非同期的に実行されます (バックグラウンドでは、サーバーと通信する必要があるため、インターネットが機能するのを待っている間、アプリを完全にブロックしても意味がありません)。

したがって、領収書を検証するためのアプローチを再考する必要があります。現在、一般的なワークフローは次のとおりです。

  1. 購入を完了する
  2. ビーブレックスに電話する
  3. 応答を待ちます
  4. ブール値をチェック

しかし、#3 はすぐに戻ってくるので、これは決してうまくいきません。次のようなことを検討する必要があります。

  1. 購入を完了する
  2. 「しばらくお待ちください…」というビューを表示するか、ユーザーが購入したもののロックを解除していることをユーザーに知らせる同様のものを表示します。
  3. ビーブレックスに電話する
  4. ブロック内で、検証が成功したかどうかを判断し、そこからコンテンツのロックを解除するため行動します。
  5. ブロックから呼び出されるまで放置する

これは手っ取り早い例です。私はコンパイルしていないので、おそらくいくつかのバグがありますが、意図した使用パターンの背後にあるアイデアが得られるはずです。

- (void) showWaitView {
    // Display a wait view
}


- (void) hideWaitView {
    // Hide the wait view
}


- (void) completeValidationWithValidateReceiptData:(NSDictionary *) receipt isRecoverableError(BOOL) isRecoverableError {
    [self hideWaitView];

    if (receipt) {
        // Unlock the content, tell the user
    } else {
        if (isRecoverableError) {
            // Probably a network error of some kind. Tell user they need to be connected,
            // and ask them to do it again.
        } else {
            // Keep the content locked, tell the user something went wrong
        }
    }
}

- (void) validateReceipt:(SKPaymentTransaction *) transaction {
    if (![BBXIAPTransaction canValidateTransactions]) {
        [self completeValidationWithValidateReceiptData:Nil isRecoverableError:YES];
        return;
    }

    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.
                [FlurryAnalytics logEvent:@"Transaction duplicate!"];
                [self completeValidationWithValidateReceiptData:Nil isRecoverableError:NO];
            } else {
                // The transaction has been successfully validated and is unique
                [FlurryAnalytics logEvent:@"Transaction verified"];
                [self completeValidationWithValidateReceiptData:bbxTransaction.validatedTransactionData isRecoverableError:NO];
            }
        } 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
                [FlurryAnalytics logEvent:@"Transaction network error"];
                [self completeValidationWithValidateReceiptData:Nil isRecoverableError:YES];
            } else {
                // The transaction supplied to the validation service was not valid according to Apple
                [FlurryAnalytics logEvent:@"Transaction invalid!!"];
                [self completeValidationWithValidateReceiptData:Nil isRecoverableError:NO];
            }
        }
    }];
}
于 2012-07-25T18:42:46.347 に答える
3

<3ブロック

- (void)verifyTransaction:(SKPaymentTransaction *)transaction completionHandler:(void (^)(BOOL flag))completionHandler
{
    if (![BBXIAPTransaction canValidateTransactions]) {
        completionHandler(YES); // There is no connectivity to reach the server
    }

    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!"];
                completionHandler(NO);
            } else {
                // The transaction has been successfully validated and is unique
                NSLog(@"Transaction valid data:%@",bbxTransaction.validatedTransactionData);
                [FlurryAnalytics logEvent:@"Transaction verified"];
                completionHandler(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"];
                completionHandler(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!!"];
                completionHandler(NO);
            }
        }
    }];
}

次に、

[instance verifyTransaction:transaction completionHandler:^(BOOL flag) {
    if (flag) {
        // YOUR CODE HERE
    }
}];

それ以外の

if ([instance verifyTransaction:transaction]) {
    // YOUR CODE HERE
}
于 2012-11-22T14:39:01.603 に答える