Objective c 检查internet连接时,数据参数为零错误

Objective c 检查internet连接时,数据参数为零错误,objective-c,ios,xcode,Objective C,Ios,Xcode,启动我的应用程序时,它会检查用户是否已订阅。如果未检测到internet连接,则会因以下错误而崩溃: 检索订阅失败,错误为“Internet连接似乎处于脱机状态”。responseString:(null)***由于未捕获异常“NSInvalidArgumentException”而终止应用程序,原因为:“数据参数为零” m 检查与framework的internet连接。在继续下一行之前,您需要检查错误。如果出现错误,请不要使用空数据调用JSONObjectWithData:方法 [self

启动我的应用程序时,它会检查用户是否已订阅。如果未检测到internet连接,则会因以下错误而崩溃:

检索订阅失败,错误为“Internet连接似乎处于脱机状态”。responseString:(null)***由于未捕获异常“NSInvalidArgumentException”而终止应用程序,原因为:“数据参数为零”

m


检查与framework的internet连接。

在继续下一行之前,您需要检查
错误。如果出现错误,请不要使用空数据调用
JSONObjectWithData
:方法

[self getPath:path
       parameters:parameters
          success:^(AFHTTPRequestOperation *operation, id responseObject) {
              if (![responseObject isKindOfClass:[NSDictionary class]])
              {
                  failureBlock(@"Invalid response received");
                  return;
              }
              NSDictionary *responseDict = (NSDictionary *)responseObject;
              if (responseDict[@"error"] == nil)
              {
                  [self saveUserDict:responseDict];
                  successBlock(responseDict);
              }
              else
              {
                  failureBlock(responseDict[@"error"]);
              }
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error) {
              if (!error) {
                  DebugLog(@"Failed to retrieve subscription with error '%@' and responseString: %@", error.localizedDescription, operation.responseString);
                  id responseObject = [NSJSONSerialization JSONObjectWithData:operation.responseData
                                                                      options:0
                                                                        error:nil];
                  failureBlock(responseObject);
              } else {
                  //handle the error scenario
                  failureBlock(@"error occured");
              }
          }];

嗯,你发布的代码只向我们展示了如果失败会发生什么,以及如何打印错误。我们需要看看在
getPath:parameters:success:failure:
method中发生了什么,看起来您需要在将错误场景传递到JSONObjectWithData方法之前处理它。我已经更新了我的答案。keep geetting epected:“错误场景的第一个括号中的错误哪一行显示了该错误?我已经更新了我的答案。在这个}结尾处,它应该有}];很抱歉,这给了我三个错误。这是我的屏幕截图。我无法查看(!error){id responseObject=[NSJSONSerialization JSONObject WithData:operation.responseData选项:0错误:nil];failureBlock(responseObject);}在屏幕截图中。请检查您复制粘贴的代码。尝试用上述代码完全替换您的代码。代码中缺少if条件。啊!这就是我错过的,现在一切都有意义了!!非常感谢你的帮助和耐心,我欠你一个人情!大加1给你!
[self getPath:path
       parameters:parameters
          success:^(AFHTTPRequestOperation *operation, id responseObject) {
              if (![responseObject isKindOfClass:[NSDictionary class]])
              {
                  failureBlock(@"Invalid response received");
                  return;
              }
              NSDictionary *responseDict = (NSDictionary *)responseObject;
              if (responseDict[@"error"] == nil)
              {
                  [self saveUserDict:responseDict];
                  successBlock(responseDict);
              }
              else
              {
                  failureBlock(responseDict[@"error"]);
              }
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error) {
              if (!error) {
                  DebugLog(@"Failed to retrieve subscription with error '%@' and responseString: %@", error.localizedDescription, operation.responseString);
                  id responseObject = [NSJSONSerialization JSONObjectWithData:operation.responseData
                                                                      options:0
                                                                        error:nil];
                  failureBlock(responseObject);
              } else {
                  //handle the error scenario
                  failureBlock(@"error occured");
              }
          }];