您好我将图片上传到我的设备上的服务器,但是在上传到服务器后它崩溃了。在代码中我已经给出了这样的规定,比如在上传图像后,它必须在添加此代码后返回到主视图,它会继续崩溃。
上传代码..
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];
}
感谢。
答案 0 :(得分:1)
我不知道您的崩溃日志,但是如果您的应用在警报后崩溃。然后问题就是委托。
您应该替换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];
答案 1 :(得分:0)
通常EXC_BAD_ACCESS
是由于内存管理不当造成的。我无法弄清楚确切的问题。但我认为你应该通过删除[alert release]
来检查它。
另外,请尝试检查是否已将UIAlertViewDelegate添加到.h文件中。