Note that there are some explanatory texts on larger screens.

plurals
  1. POMethod BOOL return from inside block
    primarykey
    data
    text
    <p>I'm trying to add Beeblex's new In App Purchase verification to my app, however i'm struggling passing a return value from within a block.</p> <p>Here's the code I have now, and as you can see I set a BOOL value, then within the verification block I set the BOOL and return it at the end. However the return at the end is called before the block finishes, so what I need is to return the BOOL from within the block?</p> <pre><code>- (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; } </code></pre> <p>If I simply put <code>return = NO;</code> inside the block, I get compiler warnings of Incompatible block pointer types, and control may reach end of non-void block.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload