
[英][__NSArrayI count]: message sent to deallocated instance iPhone
[英]-[NSConcreteMutableData release]: message sent to deallocated instance
我遇到了-[NSConcreteMutableData版本]的问题:发送到已释放实例的消息,我也附加了示例代码。
- (IBAction)uploadImage {
NSString *urlString = @"http://192.168.1.108/iphoneimages/uploadfile.php?userid=1&charid=23&msgid=3";
//if(FALSE)
for (int i=0; i<[imgArray count]; i++) {
// setting up the request object now
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
/*
add some header info now
we always need a boundary when we post a file
also we need to set the content type
You might want to generate a random boundary.. this is just the same
as my output from wireshark on a valid html post
*/
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
/*
now lets create the body of the post
*/
NSMutableData *body = [[NSMutableData data] autorelease];
NSString *str = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"ipodfile%d.jpg\"\r\n",i];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:str] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
NSData *imageData = UIImageJPEGRepresentation([imgArray objectAtIndex:i], 90);
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];
// now lets make the connection to the web
[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
//NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
//NSLog(@"%@",returnString);
[imageData release];
[request release];
//[body release];
}
}
它成功将图像上传到该文件夹,执行中没有任何错误,但是在完成处理并尝试返回时给出错误-[NSConcreteMutableData release]:消息发送到已释放实例
请帮帮我。
谢谢
UIImageJPEGRepresentation返回一个自动释放的对象,然后释放它。 自动释放时,它将炸毁。
NSMutableData *body = [[NSMutableData data] autorelease];
删除该自动发布消息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.