FHSTwitterEngine - 'NSInvalidArgumentException','data parameter is nil'

时间:2014-01-23 15:00:41

标签: ios objective-c nsjsonserialization twitpic fhs-twitter-engine

我正在使用FHSTwitterEngine将gif发布到twitpic。当我在iphone上有wifi或3G连接时,一切正常。但是我也希望在没有连接或上传失败时实现一些错误处理。因此,为了进行测试,我将iphone置于飞行模式,并尝试使用以下方法上传到twitpic:

id returned = [[FHSTwitterEngine sharedEngine] uploadImageToTwitPic:gif 
withMessage:@"message" twitPicAPIKey:@"key"];

但是当我这样做时,我立即收到以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'data parameter is nil'

然后xcode指向FHSTwitterEngine框架中的这行代码:

 id parsedJSONResponse = removeNull([NSJSONSerialization JSONObjectWithData:responseData 
options:NSJSONReadingMutableContainers error:nil]);

关于如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:7)

您可以先检查互联网连接。

Reachability *networkReachability = [Reachability reachabilityForInternetConnection];   
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];    
if (networkStatus == NotReachable) {        
    NSLog(@"There IS NO internet connection");        
} else {        

     NSLog(@"There IS internet connection");        

    }        
}