Domain = NSURLErrorDomain代码=

编程入门 行业动态 更新时间:2024-10-18 23:24:17
本文介绍了Domain = NSURLErrorDomain代码= -1001“该操作无法完成。 (NSURLErrorDomain错误-1001。)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的程序编写为从cam上传图片,示例代码如下:

#定义WEBSERVICE_URL @ 192.168.0.104/upload.php -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [选择器dismissViewControllerAnimated:YES完成:^ { UIImage * selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; NSData * imageData = UIImagePNGRepresentation(selectedImage); NSMutableURLRequest *请求= [[AFHTTPRequestSerializer序列化器] multipartFormRequestWithMethod:@ POST URLString:WEBSERVICE_URL参数:nil constructioningBodyWithBlock:^(id formData){ [formData appendPartWithFileData:imageData name:@ upfile fileName:@ test mimeType:@ image / png]; }错误:无]; AFURLSessionManager * manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; NSProgress *进度=零; NSURLSessionUploadTask * uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progresscompleteHandler:^(NSURLResponse * response,id responseObject,NSError * error){ [进度removeObserver:self forKeyPath :@ fractionCompleted]; NSLog(error.debugDescription); if(error){ [self.view updateWithMessage:[NSString stringWithFormat:@ Error:%@!,error.debugDescription]]; } else { [self.view updateWithMessage:@非常成功!]; } }]; [进度addObserver:self forKeyPath:@ fractionCompleted选项:NSKeyValueObservingOptionNew context:NULL]; [uploadTask简历]; self.imageUploadProgress = [[TNSexyImageUploadProgress alloc] init]; self.imageUploadProgress.radius = 100; self.imageUploadProgress.progressBorderThickness = -10; self.imageUploadProgress.trackColor = [UIColor blackColor]; self.imageUploadProgress.progressColor = [UIColor whiteColor]; self.imageUploadProgress.imageToUpload = selectedImage; [self.imageUploadProgress show]; [[NSNotificationCenter defaultCenter] addObserver:自我选择器:@选择器(imageUploadCompleted :)名称:IMAGE_UPLOAD_COMPLETED对象:self.imageUploadProgress]; }]; }

错误是:

TNSexyImageUploadProgressDemo [5275:113032] 错误域= NSURLErrorDomain代码= -1001 操作无法完成。 (NSURLErrorDomain错误-1001。) UserInfo = 0x7f92c2d907d0 {NSErrorFailingURLStringKey = 192.168.0.104/upload.php , NSUnderlyingError = 0x7f92c2dcd5c0 操作无法完成。(kCFErrorDomainCFNetwork错误-1001。), NSErrorFailingURLKey = h ttp://192.168.0.104/ upload.php }

无论在模拟器还是iPhone上,同样的错误,我使用野生动物园访问url,一切正确,我使用wifi访问网络。 ping 192.168.0.104是可以的。

服务器程序是用php编写的,代码令人沮丧:

100000000){ $ result_json ['error'] ='超出文件大小'; } $ finfo = new finfo(FILEINFO_MIME_TYPE); if(false === $ ext = array_search( $ finfo-> file($ _ FILES ['upfile'] ['tmp_name'])), array('png'=>'image / png'), true )){ $ result_json ['error'] ='无效的文件格式'; } if(!move_uploaded_file( $ _FILES ['upfile'] ['tmp_name'], sprintf('./ uploads /%s。% s', sha1_file($ _ FILES ['upfile'] ['tmp_name']), $ ext ))){ $ result_json ['error '] ='无法移动上传的文件'; } //立即发送结果 echo json_encode($ result_json); / * try { if(!move_uploaded_file( $ _FILES ['upfile'] ['tmp_name'], sprintf('./ uploads /%s。%s', sha1_file($ _ FILES ['upfile'] ['tmp_name']), $ ext )) ){ //抛出新的RuntimeException('无法移动上传的文件。'); } //回显json_encode(array(’succes’=> true)); } catch(RuntimeException $ e){ // echo $ e-> getMessage(); } * / ?>

github。 com / AFNetworking / AFNetworking

如果您使用的是Xcode 6,请尝试一下。

my program is write for upload the picture from the cam,sample code below:

#define WEBSERVICE_URL @"192.168.0.104/upload.php" - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:^{ UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; NSData *imageData = UIImagePNGRepresentation(selectedImage); NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id formData) { [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"]; } error:nil]; AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; NSProgress *progress = nil; NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { [progress removeObserver:self forKeyPath:@"fractionCompleted"]; NSLog(error.debugDescription); if (error) { [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]]; } else { [self.view updateWithMessage:@"Great success!"]; } }]; [progress addObserver:self forKeyPath:@"fractionCompleted" options:NSKeyValueObservingOptionNew context:NULL]; [uploadTask resume]; self.imageUploadProgress = [[TNSexyImageUploadProgress alloc] init]; self.imageUploadProgress.radius = 100; self.imageUploadProgress.progressBorderThickness = -10; self.imageUploadProgress.trackColor = [UIColor blackColor]; self.imageUploadProgress.progressColor = [UIColor whiteColor]; self.imageUploadProgress.imageToUpload = selectedImage; [self.imageUploadProgress show]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imageUploadCompleted:) name:IMAGE_UPLOAD_COMPLETED object:self.imageUploadProgress]; }]; }

the error is :

TNSexyImageUploadProgressDemo[5275:113032] Error Domain=NSURLErrorDomain Code=-1001 "The operation couldn’t be completed. (NSURLErrorDomain error -1001.)" UserInfo=0x7f92c2d907d0 {NSErrorFailingURLStringKey="192.168.0.104/upload.php", NSUnderlyingError=0x7f92c2dcd5c0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1001.)", NSErrorFailingURLKey="192.168.0.104/upload.php"}

whatever on simulator or iPhone,the same error,i use safari to access url,anything is correct,i use wifi to access network. ping 192.168.0.104 is ok.

server's program is write in php,code blelow:

100000000) { $result_json['error'] = 'Exceeded filesize'; } $finfo = new finfo(FILEINFO_MIME_TYPE); if (false === $ext = array_search( $finfo->file($_FILES['upfile']['tmp_name']), array( 'png' => 'image/png' ), true )) { $result_json['error'] = 'Invalid file format'; } if (!move_uploaded_file( $_FILES['upfile']['tmp_name'], sprintf('./uploads/%s.%s', sha1_file($_FILES['upfile']['tmp_name']), $ext ) )) { $result_json['error'] = 'Failed to move uploaded file'; } // send the result now echo json_encode($result_json); /* try { if (!move_uploaded_file( $_FILES['upfile']['tmp_name'], sprintf('./uploads/%s.%s', sha1_file($_FILES['upfile']['tmp_name']), $ext ) )) { //throw new RuntimeException('Failed to move uploaded file.'); } //echo json_encode(array('succes'=>true)); } catch (RuntimeException $e) { //echo $e->getMessage(); } */ ?>

解决方案

I was having the same problem since I started using Xcode 6. Updating the AFNetworking library fixed the problem. Everything is working fine again.

github/AFNetworking/AFNetworking

If you're using Xcode 6, give it a try.

更多推荐

Domain = NSURLErrorDomain代码=

本文发布于:2023-11-26 18:15:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634648.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   Domain   NSURLErrorDomain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!