iOS Network Connection with AFNetworking – iOS(Objective-C)
There are many libraries for iOS to connect network and get/post data. This tutorial will show one of the most popular library: AFNetworking. It is easy to implement and gather data with this library in Objective-C.
Assume that you have a data as below and you want to GET it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
{ "succes": "YES", "message": "Connected", "returnData": [{ "field1": "111", "filed2": "222", "field3": "333" }, { "field1": "111", "filed2": "222", "field3": "333" } ] } |
And this data is belong to “your.domain.com/your/path”. It is optional to divide this path as baseUrl and path like “your.domain.com” and “/your/path” for using baseUrl later. Anyway, we will get whole data and split it as success, message and returnData.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
NSURL *baseURL = [NSURL URLWithString:@"http://your.domain.com"]; NSString *path = @"/your/path"; AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL]; [manager GET:path parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) { //Network Success id JSON = responseObject; BOOL success = [[JSON objectForKey:@"success"] boolValue]; if (success) { NSArray * returnData = [JSON objectForKey:@"returnData"]; } NSString *message = [[JSON objectForKey:@"message"] stringValue]; NSLog(@"%@", message); } failure:^(NSURLSessionDataTask *task, NSError *error) { //Network Failure }]; |
returnData array contains all values of field1, field2, field3.
©Coffee Break Codes – Simple Network Connection with AFNetworking – iOS(Objective-C)
Toᥙche. Outstanding arguments. Keep up tһe аmаzing
spirit.
Привет меня зовут Jaimie Wylly тороплюсь
поделится счастливым событием я прошел регистрацию 1.
Вам тоже рекомендую, до встречи.
Жду всех посетителей блога iOS Network Connection with AFNetworking – Objective-C | Coffee Break Codes .
Сайт 1
I’m really enjoying the theme/design of your web site. Do you ever run into any internet browser compatibility problems?
A handful of my blog readers have complained about my blog not working correctly in Explorer but looks great in Chrome.
Do you have any advice to help fix this issue?
https://t-do.ru/privatznakomstva – Одноразовые встречи
Телеграм канал для тех кто дорожит свой конфиденциальностью.
Подписывайся, не пожалеешь 😉