シミュレーターでアプリを実行すると、すべてが完全に機能します。しかし、Ipad で同じアプリを実行すると、例外がスローされます。
キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。理由: 'データ パラメータが nilです。私のアプリでは、あるステップで web-URl を要求し、返されたJSON
応答を解析する必要があります。しかし、web-url を確認したところ、シミュレーターで完全に解析できました。しかし、すべての問題は実際のiOSデバイスで発生しています.しかし、私はそれが間違っているコードを特定したと思います.
+ (NSDictionary*) getParsedJSON:(NSString*) urlString {
NSLog(@"################################################################################");
NSLog(@"getParsedJSON => urlString:");
NSLog(@"%@", urlString);
NSURL* url = [NSURL URLWithString:urlString];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
NSURLResponse *response1 = nil;
NSError *error = nil;
NSData* response = [NSURLConnection sendSynchronousRequest:request returningResponse:&response1 error:&error];
//NSData* response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"--------------------------------------------------------------------------------");
NSString* responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog(@"getParsedJSON => responseString:\n%@", responseString);
NSLog(@"--------------------------------------------------------------------------------");
NSError* jsonParsingError = nil;
NSDictionary* parsedJSON = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError]; // here is place where exception seems to be thrown.
if (jsonParsingError) {
NSLog(@"ERROR in parsing JSON: %@", jsonParsingError);
} else {
NSLog(@"getParsedJSON => parsedJSON: \n%@", [parsedJSON description]);
}
NSLog(@"################################################################################");
return parsedJSON;
}
間違っていると思われる行を特定しました。例外レポートのスクリーンショットも添付しました。経験豊富な回答をお待ちしております。