EXC_BAD_ACCESS在另一个块内执行块

时间:2017-01-11 23:14:46

标签: ios block objective-c-blocks exc-bad-access

我正在处理一些遗留代码,这些代码在另一个内部调用一串块。我不时随机发生EXC_BAD_ACCESS崩溃,我无法弄清楚原因。

/

*
     Description: Submit type card transaction to MCM server.
     */
    - (void)submitTypeTransactionWithRequest:(ChargeRequest *)request completion:(void (^)(BOOL))completion {

        //login to gateway to begin transaction
        [self loginRoamServerWithCompletion:^(BOOL success) {
            if (success) {

                //make the payment
                Payment *responsePayment = [self makePayment];

                //if cvv is invalid, decline the transaction
                [self voidTxnWhenCVV2OrAVSInvalid:responsePayment completion:^(BOOL isValidCVV) {
                    if (completion) {
                        completion(isValidCVV);
                    }
                }];
            }
        }];
    }

    - (void)loginRoamServerWithCompletion:(void (^)(BOOL success))completion {
        ....

        [self rpxLogonSuccessfulWithCompletion:^(BOOL success) {
            if (completion) {
                completion(success);
            }
        }];
    }

- (void)voidTxnWhenCVV2OrAVSInvalid:(RpxPayment *)responsePayment completion:(void (^)(BOOL isValidCVV))completion {

        //This method is now called second time in the flow
        [self loginRoamServerWithCompletion:^(BOOL success) {
            if (success) {
               BOOL result = [self voidPayment];
               if (completion) {
                  completion(result);
               }
            }
        }];
    }
    - (void)rpxLogonSuccessfulWithCompletion:(void (^)(BOOL success))completion { 

     // at this point, when this method is called the second time => 'EXC_BAD_ACCESS'(completion = NULL)

        BOOL result = [self login]
        if (completion) {
           completion(result);
        }
    }

这就是流程的工作原理。第一个电话是submitTypeTransactionWithRequest。然后调用loginRoamServerWithCompletion,然后调用rpxLogonSuccessfulWithCompletion。事务完成后,如果CVV无效,则调用voidTxnWhenCVV2OrAVSInvalid以使事务无效。这又会再次调用loginRoamServerWithCompletion,调用rpxLogonSuccessfulWithCompletion。当第二次调用rpxLogonSuccessfulWithCompletion时,代码会随着EXC_BAD_ACCESS错误而随机崩溃。根据堆栈跟踪,completion块的值为NULL。

Attaching the stack trace

0 个答案:

没有答案