將圖片寫入手機相冊: UIImageWriteToSavedPhotosAlbum(##圖片##, nil, nil, nil);
1.依賴 Reachability
2.依賴3個庫
? SystemConfiguration.framework
? MobileCoreServices.framework
? libz.1.2.5.dylib
/**************** 下載 ******************/
1. 創建請求對象
NSURL *url = [NSURL URLWithString:##需要下載的文件路徑##];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
2. 下載後文件所在路徑
NSString *path = ##下載後文件所在路徑##;
request.downloadDestinationPath = path;
3.1 設置下載進度代理(需要遵循協議:ASIDownloadProgressDelegate)
>1. request.downloadProgressDelegate = self;
>2. 實現下載進度代理方法
- (void)setProgress:(float)newProgress{
NSLog(@"當前下載進度: %f", newProgress);
}
// 上面2步可以一步解決
request.downloadProgressDelegate = self.progressView;
4. 支持斷點下載
request.allowResumeForFileDownloads = YES;
5. 發送請求
[request startAsynchronous];
/**************** 上傳 ******************/
1.創建請求
NSURL *url = [NSURL URLWithString:##需要下載的文件路徑##];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
2. 指定所要上傳文件的路徑
[request setFile:file ofKey:@"file"];
3. 設置其他參數
[request setPostValue:@""];
1. 取得默認的緩存對象
ASIDownloadCache *cache = [ASIDownloadCache sharedCache];
2. 設置緩存策略
- (void)setDefaultCachePolicy:(ASICachePolicy)cachePolicy;
3. 設置緩存路徑
- (void)setStoragePath:(NSString *)path;
AFHTTPRequestOperationManager *man = [AFHTTPRequestOperationManager manager];
[man GET:##地址## parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"請求成功");
} failure: ^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"請求失敗");
}];
AFNetworkReachabilityManager *man = [AFNetworkReachabilityManager sharedManager];
[man setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown: // 未知網絡
break;
case AFNetworkReachabilityStatusNotReachable: // 沒有網絡
break;
case AFNetworkReachabilityStatusReachableViaWiFi: // wifi網絡
break;
case AFNetworkReachabilityStatusReachableViaWWAN: // 手機自帶網絡
break;
default:
break;
}
}];
[man startMonitoring];
UIIimagePickerController *ipc = [[UIIimagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:ipc animated:YES completion:nil];
OC中執行JavaScript代碼
[self.webView stringByEvaluatingJavaScriptFromString:##JS代碼##];