objective-c - 获取 &error 没有错误

标签 objective-c ios nsurlconnection nserror

出于某种原因,当我执行 NSURLConnection 时没有错误存在,但我收到错误。

NSLog(@"Sending string to server. ID:11118");
    NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSLog(@"Response from server received. ID:11119");
    NSString *responseString = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

if (&error)
    {
        //Handle Error
        NSLog(@"Error getting a server response! (scm) Error %i: %@", [error code], [error localizedDescription]);
        UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"Error getting a server response!" message:[NSString stringWithFormat:@"Error %i: %@", [error code], [error localizedDescription]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [theAlert show];
    }

[error code] 显示 0[error localizedDescription] 显示 Null >.

有什么想法吗?

最佳答案

不要检查 NSError 对象来确定是否发生了错误。按照惯例,您应该检查产生错误的方法的返回值。如果结果为 nilNO,那么您才应该继续检查错误。此外,您不是在检查错误对象,而是在检查错误对象内存中地址的有效性。

在您的情况下,仅当 urlDatanil 时才继续检查错误。

关于objective-c - 获取 &error 没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8438253/

相关文章:

iphone - 使用 Core Motion 和 CATransform3D 旋转图像

ios - 添加超过 4 个 subview 时自动布局无法满足约束

ios - 保存到相机胶卷时向照片添加文本字符串

swift - 在 Swift 中为 SOAP POST 从 NSURLConnection 迁移到 NSURLSession

iphone - NSURL 连接和 json

Objective-C协程

ios - 其他角度线宽

ios "has active assertions beyond permitted time:"异步任务崩溃

iphone - 使用 Quartz CGContextFillEllipseInRect 绘制两个圆

ios - flutter:如果 app delegate swizzling 被禁用,UIApplicationDelegate 收到的远程通知需要转发到 FIRAuth 的