今天看啥
热点:

AFNetworking与MJExtension处理后台_图片框架SDWebImage(初稿),


1.AFNetworking框架处理用户一般的POST GET等5种类型的请求

GET请求:

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请求:

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.MJExtension用户直接处理Dictionary与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
对应的json:
"statuses": [
{
"id": 11488058246,
"text": "求关注。",
...

"user": {
"id": 1404376560,
"name": "zaku",
"description": "人生五十年,乃如梦如幻;有生斯有死,壮士复何憾。",
"url": "http://blog.sina.com.cn/zaku",
"profile_image_url": "http://tp1.sinaimg.cn/1404376560/50/0/1",
...
}
},
...
]
如下示例将json转换成数据,转换如下:

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

3.图片显示框架SDWebImage

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


应用无内存时 关闭下载清理内存

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


www.bkjia.comtruehttp://www.bkjia.com/Androidjc/1005149.htmlTechArticleAFNetworking与MJExtension处理后台_图片框架SDWebImage(初稿), 1.AFNetworking框架处理用户一般的POST GET等5种类型的请求 GET请求: AFHTTPRequestOperation...

相关文章

    暂无相关文章
相关搜索:

帮客评论

视觉看点