インターネットから HTML ファイルをダウンロードし、アプリに保存して後で (オフラインで) 表示しようとしています。次の方法を使用してファイルをダウンロードしましたが、データがダウンロードされていないと NSLogs が報告しています。ここで何が問題なのですか?(アクティブなインターネット接続を想定し、ローカル ドキュメント ディレクトリへの事前定義されたパスを想定します)
urlAddress = @"http://subdomain.somesite.com/profile.html";
// Create and escape the URL for the fetch
NSString *URLString = [NSString stringWithFormat:@"%@%@", @"ttp://subdomain.somesite.com/profile.html"];
NSURL *URL = [NSURL URLWithString:
[URLString stringByAddingPercentEscapesUsingEncoding:
NSASCIIStringEncoding]];
// Do the fetch - blocks!
NSData *theData = [NSData dataWithContentsOfURL:URL];
if(theData == nil) {
NSLog(@"NO DATA DOWNLOADED");
}
// Do the write
NSString *filePath = [[self documentsDirectory] stringByAppendingPathComponent:@"Profile/profile.html"];
[theData writeToFile:filePath atomically:YES];
NSLog(@"WRITING profile.html to path %@!", filePath);