我正在尝试将我的应用中的照片上传到网络服务中。
我试图创建的流程如下:
- 用户用相机拍照
- 照片保存到自定义相册下的相机胶卷
- 已保存照片的 URL 已提供给我的商店
- 商店尝试将照片上传到 Web 服务。
我正在尝试使用NSData *data = [NSData dataWithContentsOfURL:[item assetURL]]
where item 是包含相关 URL 的模型。但是,即使它产生了 URL,当我记录它时,这条线也不会产生数据:"assets-library://asset/asset.PNG?id=28DBC0AC-21FF-4560-A9D6-5F4BCA190BDB&ext=PNG"
代码片段如下:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:^(void){
[library writeImageToSavedPhotosAlbum:image.CGImage orientation:image.imageOrientation completionBlock:^(NSURL* assetURL, NSError* error) {
BCard *card = [[BCard alloc]init];
//error handling
if (error!=nil) {
NSLog(@"[ERROR] - %@",error);
return;
}
//add the asset to the custom photo album
[library addAssetURL: assetURL
toAlbum:@"Business Cards"
withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(@"Custom Album Error: %@", [error description]);
}
}];
[card setAssetURL:assetURL];
[[BCardStore sharedStore]addToQueue:card];
int index = [[[BCardStore sharedStore]getQueue]count]-1;
[[BCardStore sharedStore]uploadItemAtIndex:index withProgressBlock:nil withExitBlock:nil];
}];
}];
}
和
-(void)uploadItemAtIndex:(NSUInteger)index withProgressBlock:(progressBlock)pBlock withExitBlock:(exitBlock)eBlock
{
BCard *item = [uploadQueue objectAtIndex:index];
NSURL *url = [NSURL URLWithString:@"http://192.168.0.116:8080"];
NSData *data = [NSData dataWithContentsOfURL:[item assetURL]];
AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url];
numberedName = numberedName +1;
NSString *name = [NSString stringWithFormat:@"%d",numberedName];
NSLog(@"%@",[item assetURL]);
//upload data using AFNetworking here
}
该片段[library addAssetUrl:NSUrl toAlbum:NSString withCompletionBlock:^(NSError *error)]
来自我在这里找到的类别。
我真的在这里得到了正确的 URL 还是我使用dataWithContentsOfURL
不正确?