简体   繁体   English

将映像上传到服务器IOS7后,应用程序崩溃

[英]App Getting Crash After Uploading the Image to Server IOS7

Hi I'm uploading the image to my server form my device but its getting crash after its get uploaded to server. 嗨,我正在将图像从设备上传到服务器,但是在将图像上传到服务器后却崩溃了。 In code i have given the provision like after uploading the image it has to go back to the main view after adding this code its keep getting crash. 在代码中,我给出了类似的规定,即在上传图像后,必须在添加此代码后返回主视图,使其不断崩溃。

Upload Code.. 上传代码..

    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];

     }
   }

The app gets crash after the alert message pops up when i click the OK in alert message app gets crash Please tell me how to resolve this one. 当我单击警报消息中的“确定”应用程序崩溃时,警报消息弹出后,应用程序崩溃。请告诉我如何解决此问题。

  -(void)showAlert{

     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Thanks" message:@"For uploading Image" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil];
     [alert show];
     [alert release];
    }

Thanks. 谢谢。

I don't know your crash log but if your app crash after alert. 我不知道您的崩溃日志,但是如果您的应用在警报后崩溃了。 then the problem will be delegate. 那么问题将被委托。

You should replaces delegate=nil instead of delegate=self 您应该替换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];

Generally EXC_BAD_ACCESS is due to improper memory management . 通常EXC_BAD_ACCESS是由于不正确的内存管理。 I cant figure out exact problem . 我不知道确切的问题。 But I think you should just check that by removing [alert release] . 但是我认为您应该通过删除[alert release]

Also try check if you have add UIAlertViewDelegate to .h file . 另外,请尝试检查是否已将UIAlertViewDelegate添加到.h文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM