使用 UIImageJPEGRepresentation 将 UIImage 上传到服务器
我正在编写一个将 UIImage 上传到我的服务器的应用程序。这很完美,因为我看到添加了图片。我使用 UIImageJPEGRepresentation 作为图像数据并配置 NSMutableRequest。 (设置 url、http 方法、边界、内容类型和参数)
我想在上传文件时显示 UIAlertView,我编写了以下代码:
//now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"return info: %@", returnString);
if (returnString == @"OK") {
NSLog(@"you are snapped!");
// Show message image successfully saved
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"You are snapped!" message:@"BBC snapped your picture and will send it to your email adress!" delegate:self cancelButtonTitle:@"OK!" otherButtonTitles:nil];
[alert show];
[alert release];
}
[returnString release];
returnString 输出:2010-04-22 09:49:56.226 bbc_iwh_v1[558: 207] return info: OK
问题是我的 if 语句没有说 returnstring == @"OK" 因为我没有得到 AlertView。
我应该如何检查这个返回字符串值?
I'm writing an app which uploads a UIImage to my server. This works perfect, as I see the pictures being added. I use the UIImageJPEGRepresentation for the image data and configure an NSMutableRequest. ( setting url, http method, boundary, content types and parameters )
I want to display an UIAlertView when the file is being uploaded and I wrote this code:
//now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"return info: %@", returnString);
if (returnString == @"OK") {
NSLog(@"you are snapped!");
// Show message image successfully saved
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"You are snapped!" message:@"BBC snapped your picture and will send it to your email adress!" delegate:self cancelButtonTitle:@"OK!" otherButtonTitles:nil];
[alert show];
[alert release];
}
[returnString release];
The returnString outputs: 2010-04-22 09:49:56.226 bbc_iwh_v1[558:207] return info: OK
The problem is that my if statements does not say returnstring == @"OK" as I don't get the AlertView.
How should I check this returnstring value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于 returnString 是一个指针:
当您说:
您正在尝试比较两个指针,而不是两个字符串。
比较字符串的正确方法是:
The problem is that returnString is a pointer:
When you say:
you are trying to compare two pointers, not two strings.
The right way to compare strings is: