【问题标题】:Uploading UIImage to server using UIImageJPEGRepresentation使用 UIImageJPEGRepresentation 将 UIImage 上传到服务器
【发布时间】:2010-09-01 17:02:57
【问题描述】:

我正在编写一个将 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] 返回信息:OK

问题是我的 if 语句没有说 returnstring == @"OK" 因为我没有得到 AlertView。

我应该如何检查这个返回字符串值?

【问题讨论】:

    标签: uiimage uploading nsmutableurlrequest uiimagejpegrepresentation


    【解决方案1】:

    问题是returnString是一个指针:

    NSString * returnString;
    

    当你说:

    if ( returnString == @"OK" )
    

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

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

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

    【讨论】:

      猜你喜欢
      • 2015-07-24
      • 2013-07-02
      • 2011-10-10
      • 2011-02-23
      • 2013-02-20
      • 1970-01-01
      • 2013-10-29
      • 2020-12-13
      • 1970-01-01
      相关资源
      最近更新 更多