0

I am trying to get data through JSON approach using nsurlsessiondatatask but I am unable to get the data out of the data task completion handler.

Please help????

Akash IOS
  • 1
  • 6

1 Answers1

0

NSURLSessionDataTask has a method called resume. Make sure you call it after you create your data task object.

NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@""] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
    NSLog(@"%@", response);
}];
[task resume];
  • yes I did called but data inside completion handler iam unable to use. – Akash IOS May 30 '17 at 08:50
  • NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; for(int i=0;i<=10;i++){ NSString *date = [[[json objectForKey:@"response"]objectAtIndex:i]objectForKey:@"date"]; NSLog(@"Date Content : %@",date); self.dayDate = [date substringToIndex:2]; NSLog(@"day date content is %@",self.dayDate); self.dateAdder=self.dayDate; NSLog(@"date Adder : %@",self.dateAdder); } NSLog(@"date Adder Before datatask : %@",self.dateAdder); [dataTask resume]; – Akash IOS May 30 '17 at 08:54
  • @AkashIOS, can you post the format of the json data that you get from remote call? – Surendra Patidar Jun 07 '17 at 10:53
  • I am getting the data in the form of nsdictionary which is perfectly fine but the main problem iam getting is data is becoming nil at first instance as I am supposed to use this data in didselectrowatindex tableview delegate method. – Akash IOS Jun 07 '17 at 11:12
  • Have you declared property dateAdder strong? – Surendra Patidar Jun 07 '17 at 11:39