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