IOS AFNetworking配置进IOS

时间:2023-03-09 09:49:04
IOS AFNetworking配置进IOS

IOS AFNetworking配置进IOS

Prefix Header 中填入绝对路径

//PCH 里面加入这个写代码
#ifndef TARGET_OS_IOS
#pragma mark ---------- for AFNetwork start --------
#ifndef TARGET_OS_IOS
#define TARGET_OS_IOS TARGET_OS_IPHONE
#endif
#ifndef TARGET_OS_WATCH
#define TARGET_OS_WATCH 0
#endif

AFNetworking文件链接:https://github.com/mojie123/AFNetworking

调用

NSString* str=[NSString stringWithFormat:@"https://api.weibo.com/2/comments/to_me.json?source=%@&access_token=%@",appKey, access_token ];
AFHTTPSessionManager* manager = [AFHTTPSessionManager manager];
//第二参数是需要传进去的链接参数
[manager GET:str parameters:nil success:^(NSURLSessionDataTask* task ,id responseObeject){
// CM_ToMy_data* data=[CM_ToMy_data mj_objectWithKeyValues:dataDit]; NSArray* C_arr=[responseObeject objectForKey:@"comments"];
CM_CommentData* commen=[CM_CommentData new];
m_arr=[commen dicCommentData:C_arr];
[self data];
NSLog(@"评论获取成功");
}failure:^(NSURLSessionDataTask* task ,NSError* error){
NSLog(@"获取失败");
}];

MJExtension文件链接:https://github.com/mojie123/MJExtension