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]; }