2017-01-23 2 views
-1

앱에서 API를 눌렀을 때 API가 작동 중입니다. 시뮬레이터 및 장치에서 앱을 삭제할 때 업데이트 된 응답이 표시되지 않습니다. 잘못된 작업을 수행하는 것이 잘못된 것입니다. 나는 이미 Afnetworking 간단한 Api nsurl 세션을 시도했다.Api가 정상적으로 작동하지 않습니다.

NSString *strURL = [NSString stringWithFormat:@"https://mysponsers.com/m/comments/publicpost/674"]; 

    NSURL *url = [NSURL URLWithString:strURL]; 
    AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url]; 
    [httpClient getPath:strURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { 
    id json = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:nil]; 

     NSLog(@"RESPONSE--->1%@",json); 
    } failure:^(AFHTTPRequestOperation* operation, NSError *error) { 
     //fail! 
     NSLog(@"Error String is %@", error.localizedDescription); 

    }]; 

여기 코드는 api를 치기 위해 afnetworkikng를 사용하고 있습니다.
고마워요

+1

obtC 관련 질문이 없습니다. –

+0

무슨 일입니까? – shallowThought

+0

어떤 AFNetworking 버전을 사용하고 있습니까? –

답변

0

AFNetworking 라이브러리의 최신 버전을 사용해 보거나이 코드를 사용할 수도 있습니다.

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://mysponsers.com/m/comments/publicpost/674"] 
                 cachePolicy:NSURLRequestUseProtocolCachePolicy 
                timeoutInterval:10.0]; 
[request setHTTPMethod:@"GET"]; 

NSURLSession *session = [NSURLSession sharedSession]; 
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 
              completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 
               if (error) { 
                NSLog(@"%@", error); 
               } else { 
                NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 
                NSLog(@"%@", httpResponse); 
               } 
              }]; 
[dataTask resume]; 
+0

당신의 지원에 감사드립니다. –

+0

나는 그것이 작동하지 않는 동일한 문제에 직면하고있다. –

0

당신은 설치하거나 업데이트가 포드 파일 ('~> 3.1.0'포드 'AFNetworking')이 추가 cocoapods를 통해 AFNetworking.

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; 
    manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 

    AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer]; 

    // Change your api content-type here: 
    [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 

    manager.requestSerializer = requestSerializer; 

    [manager GET:@"{ Write your url here }" 
     parameters:nil 
     progress:nil 
     success:^(NSURLSessionDataTask *operation, id responseObject) { 
      NSString *response = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; 
      NSLog(@"Success response: %@", response); 
     } 
     failure:^(NSURLSessionDataTask *operation, NSError *error) { 
      NSHTTPURLResponse *response = (NSHTTPURLResponse *)operation.response; 
      NSLog(@"Failure response: %@", response); 
     }]; 
관련 문제