使用 UIImageJPEGRepresentation 将 UIImage 上传到服务器

发布于 2024-08-30 00:18:46 字数 1058 浏览 5 评论 0原文

我正在编写一个将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

A君 2024-09-06 00:18:46

问题在于 returnString 是一个指针:

NSString * returnString;

当您说:

if ( returnString == @"OK" )

您正在尝试比较两个指针,而不是两个字符串。

比较字符串的正确方法是:

if ([returnString isEqualToString:@"OK"])
{
    //do what you want
}

The problem is that returnString is a pointer:

NSString * returnString;

When you say:

if ( returnString == @"OK" )

you are trying to compare two pointers, not two strings.

The right way to compare strings is:

if ([returnString isEqualToString:@"OK"])
{
    //do what you want
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文