How to get data to return from NSURLSessionDataTask

后端 未结 4 808
夕颜
夕颜 2020-12-16 05:16

I have a registration view controller which handles all the user input and calls a function in another class (wsClass) passing to it, that data as an NSDictionary.

T

4条回答
  •  星月不相逢
    2020-12-16 06:10

    Try this . This will work well.

    -(void)loadDetails
    {
    
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    [[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    
    
        _allVehicleLocationsArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    
        [self afterCompleteDoThis];
    
    
    }] resume];
    
    
    }
    
    -(void)afterCompleteDoThis{
    
    for (NSDictionary *vehicleDict in _allVehicleLocationsArray) {
    
        NSLog(@" PPP %@" , [vehicleDict valueForKey:@"vehicleType"]);
    
    }
    }
    

提交回复
热议问题