执行被中断,原因是:EXC_BAD_ACCESS(代码= EXC_I386_GPFLT)。

时间:2016-02-24 11:08:44

标签: objective-c sdwebimage

在我的应用程序中,我想在那时从服务器加载图像,这个错误显示在我的控制台上。

这是我的一些代码。

/**
 *  Services gateway
 *  Method  get response from server
 *  @parameter              -> object: request josn object ,apiName: api endpoint
 *  @returm                 -> void
 *  @compilationHandler     -> success: status of api, response: respose from server, error: error handling
 */
+ (void)getDataWithObject:(NSDictionary *)object onAPI:(NSString *)apiName withController:(UIViewController*)controller
                         :(void(^)(BOOL success,id response,NSError *error))compilationHandler {


    controller = controller;
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    // set request type to json
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];


    // post request to server
    [manager POST:apiName parameters:object success:^(AFHTTPRequestOperation *operation, id responseObject) {

        // NSError *error;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:responseObject
                                                           options:0
                                                             error:&error];

        //NSString *JSONString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding];
        //// 

        // check the status of API
        NSDictionary *dict = responseObject;
        NSString *statusOfApi = [[NSString alloc]initWithFormat:@"%@"
                                 ,[dict objectForKey:@"OK"]];

        // IF Status is OK -> 1 so complete the handler
        if ([statusOfApi isEqualToString:@"1"] ) {

            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            compilationHandler(TRUE,responseObject,nil);

        } else {

            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

            NSArray *errorMessages = [responseObject objectForKey:@"messages"];
            NSString *message = [errorMessages objectAtIndex:0];

            [Utilities showAlertViewWithTitle:apiName message:message];

            compilationHandler(FALSE,responseObject,nil);
        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSString *message = [NSString stringWithFormat:@"%@",[error localizedDescription]];
        NSLog(@"Message is %@", message);

        NSString *errorMessage = [NSString stringWithFormat:@"%@",[error localizedDescription]];
        if (!([message rangeOfString:@"The request timed out."].location == NSNotFound)) {
            [Utilities showAlertViewWithTitle:apiName message:errorMessage];
        }

        compilationHandler(FALSE,errorMessage,nil);
    }];

}

Plz帮帮我。

答案

在我的代码中我错过了http://

0 个答案:

没有答案