嗨,我正在将图像从设备上传到服务器,但是在将图像上传到服务器后却崩溃了。在代码中,我给出了类似的规定,例如在上传图像后,必须在添加此代码后返回主视图,使其不断崩溃。
上载验证码
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=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];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句