您好,我正在将图像从我的设备上传到我的服务器,但在上传到服务器后它崩溃了。在代码中,我已经给出了这样的规定,比如在上传图像后它必须在添加此代码后返回主视图,它一直在崩溃。
上传代码..
NSString *urlString = @"http://indianpoliticalleadersmap.com/IOS/upload/photos/upload.php";
NSData *imageData = UIImageJPEGRepresentation(imageview.image,90);
long imageSize = imageData.length;
NSLog(@"SIZE OF IMAGE: %.2f Mb", (float)imageSize/1024/1024);
if (imageSize > 4.194e+6) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sorry" message:@"your image exceeds more then 4mb pls upload below 4mb image" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
else
{
NSString *urlString = @"url";
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc]init]autorelease];
[request setURL:[NSURL URLWithString:urlString]] ;
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary]dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n"dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary]dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@data",returnString);
[self temp];
[self performSelector:@selector(myMethod) withObject:nil afterDelay:3.0f];
[self performSelector:@selector(dissMissViewController) withObject:self afterDelay:4.0f];
alertTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showAlert) userInfo:nil repeats:NO];
}
}
当我在警告消息中单击“确定”时弹出警告消息后应用程序崩溃应用程序崩溃请告诉我如何解决此问题。
-(void)showAlert{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Thanks" message:@"For uploading Image" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil];
[alert show];
[alert release];
}
谢谢。
最佳答案
我不知道你的崩溃日志,但如果你的应用程序在警报后崩溃。那么问题将是委托(delegate)。
您应该替换 delegate=nil
而不是 delegate=self
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sorry" message:@"your image exceeds more then 4mb pls upload below 4mb image" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
关于ios - 将图像上传到服务器 IOS7 后应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22396130/