AFNetworking and MJExtension processing backend _ image framework SDWebImage (first draft ),

Source: Internet
Author: User

AFNetworking and MJExtension processing backend _ image framework SDWebImage (first draft ),

1. The AFNetworking Framework processes five types of requests, such as post get.

GET request:

AFHTTPRequestOperationManager *mgr=[AFHTTPRequestOperationManager manager];        NSMutableDictionary *params=[NSMutableDictionary dictionary];    [params setObject:account.access_token forKey:@"access_token"];        [mgr GET:@"https://api.weibo.com/2/statuses/friends_timeline.json" parameters:params success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {                NSArray *newStatus=[WBStatus objectArrayWithKeyValuesArray:responseObject[@"statuses"]];        NSIndexSet *set=[[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(0, newStatus.count)];        [self.statues insertObjects:newStatus atIndexes:set];        [self.tableView reloadData];            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {        NSLog(@"%@",[error localizedDescription]);    }];

POST request:

AFHTTPRequestOperationManager *mgr=[AFHTTPRequestOperationManager manager];        NSMutableDictionary *param=[NSMutableDictionary dictionary];    [param setObject:@"43435345453 forKey:@"client_id"];    [param setObject:@"354083454f535fv53c53d97" forKey:@"client_secret"];    [param setObject:@"authorization_code" forKey:@"grant_type"];    [param setObject:@"http://www.baidu.com" forKey:@"redirect_uri"];    [param setObject:code forKey:@"code"];        [mgr POST:@"https://api.weibo.com/oauth2/access_token" parameters:param success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {            }];

2. The MJExtension user directly processes the conversion between the Dictionary and Bean.

#import <Foundation/Foundation.h>#import "WBUser.h"@interface WBStatus : NSObject@property (nonatomic,copy) NSString *text;@property (nonatomic,copy) NSString *idStr;@property (nonatomic,strong) WBUser *user;@end
Corresponding json:
"Statuses": [{"id": 11488058246, "text": "follow. ",... "User": {"id": 1404376560, "name": "zaku", "description": "If you have lived for fifty years, it's like a dream, what do you regret. "," Url ":" http://blog.sina.com.cn/zaku "," profile_image_url ":" http://tp1.sinaimg.cn/1404376560/50/0/1 ",...},...]
The following example converts json into data:

#import "MJExtension.h"NSArray *newStatus=[WBStatus objectArrayWithKeyValuesArray:jsonStr];

3. Image Display framework SDWebImage

#import "UIImageView+WebCache.h"NSURL *url=[NSURL URLWithString:urlStr];UIImage *placehoder = [UIImage imageNamed:@"default_image"];[imageView sd_setImageWithURL:url placeholderImage:placehoder];


Disable download and clear memory when the application has no memory

-(void)applicationDidReceiveMemoryWarning:(UIApplication *)application{    SDWebImageManager *mgr=[SDWebImageManager sharedManager];        [mgr cancelAll];        [mgr.imageCache clearMemory];    }


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.