将IPAD切换到IPAD AIR错误线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x384e344432212301)

时间:2015-12-03 14:52:16

标签: ios objective-c ipad afnetworking

我绝望了,
我有一个在IPAD,IPAD 2甚至在IPAD Air Simulator上运行良好的IOS应用程序,但是尝试在IPAD AIR设备上运行此APP,应用程序在发出HTTPS请求并获取一些数据时崩溃。 对于HTTPS请求,我使用AFNetworking Framework。 有任何想法或一些经验与类似的问题? 我已经阅读了很多关于stackoverflow的文章,并试图寻找一个僵尸,但没有找到。

- (void) executeRequestType:(RequestType)type_
              requestMethod:(RequestMethod)method_
                     layout:(NSString *)layout_
                     action:(NSString *)action_
                 parameters:(NSDictionary *)params_
               successBlock:(SuccessBlock)success_ {

    _status = RequestStatusInitate;

    //NSLog(@"%@ - %@ - %@", layout_, params_, action_);
    NSString *parmstr = @"";
    if (params_) {
        parmstr = [self parmeterStringFromDictionary:params_];
    }
    NSString *strURL = [NSString stringWithFormat:@"%@fmi/xml/fmresultset.xml?-db=%@&-lay=%@%@&%@",SERVER_URL,DB_NAME, layout_, parmstr, action_];
    NSLog(@"request str %@", strURL);

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    NSURL *url = [NSURL URLWithString:strURL];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    if (method_ == RequestMethodDelete) {
        [request setHTTPMethod:@"DELETE"];
    }

    AFXMLRequestOperation *operation = [AFXMLRequestOperation
                                        XMLParserRequestOperationWithRequest:request
                                        success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {

                                            NSLog(@"%li",(long)response.statusCode);

                                            NSObject *object = success_(XMLParser);
                                            NSString *requestType = [NSString stringWithFormat:@"%d", type_];
                                            NSDictionary *responseDict;
                                            responseDict = @{ DATA: object,
                                                        REQUEST_TYPE: requestType};
                                            _status = RequestStatusCompleted;
                                            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
                                            objc_msgSend(_delegate, @selector(callerDidFinishLoading:receivedObject:), self, responseDict); 
        //Trying to call "callerDidFinishLoading" EXC_BAD_ACCESS is Thrown
    }
                                        failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser) {

                                            _status = RequestStatusCompleted;
                                            NSLog(@"%@",error);
                                            objc_msgSend(_delegate, @selector(caller:didFailWithError:), self, error);
                                            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

                                                                                           }];

    [operation start];


    _status = RequestStatusInProgress;

}

1 个答案:

答案 0 :(得分:2)

为什么使用objc_msgSend来调用委托方法?

您需要更改:

objc_msgSend(_delegate, @selector(callerDidFinishLoading:receivedObject:), self, responseDict);

为:

[_delegate callerDidFinishLoading:self receivedObject:responseDict];

如果它是一个选项委托方法,那么:

if ([_delegate respondsToSelector:@selector(callerDidFinishLoading:receivedObject:)]) {
    [_delegate callerDidFinishLoading:self receivedObject:responseDict];
}