2015-05-09 60 views

回答

2

看看流行的AFNetworking網絡庫。這提供了完整的網絡功能和非常完善的文檔代碼。雖然您也可以使用Apple's networking APIs

簡單AFNetworking例如:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 
manager.requestSerializer = [AFJSONRequestSerializer serializer]; 

NSDictionary *params = @{@"q":@"Chicago", 
         @"units":@"imperial", 
         @"type":@"like", 
         @"mode":@"json" 
         }; 

    [manager GET:@"http://api.openweathermap.org/data/2.5/weather" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { 

     //Success 

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

     //Failure 

    }];