AFN的上传:
AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
NSString *str = @"你的地址";
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"username"] = @"zhangdanfeng";
NSData *data = UIImageJPEGRepresentation(self.imageView.image, 1);
[mgr POST:str parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFileData:data name:@"file" fileName:@"zhang.jpg" mimeType:@"image/jpeg"];
} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
网络监听
AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
[mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WIFI");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"3G");
break;
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"NO NETWORK");
break;
case AFNetworkReachabilityStatusUnknown:
NSLog(@"WEIZHI");
break;
default:
break;
}
}];
[mgr startMonitoring];
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。