1

このコードはシミュレーターで問題なく動作し、ファイルを書き出します。

ただし、iPhone では、ファイルは書き出されません。

DLog(@"");

timeStart  = [NSDate date];


NSURL *url = [NSURL URLWithString:SAT_URL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:FILE_NAME];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

    DLog(@"updated words to: %@",path);
    //DLog(@"response: %@",responseObject);

    [self processWords];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    // Deal with failure
}];

[operation start];

rawWords と行はすべてデバイス上で null です:

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:FILE_NAME];
NSString *rawWords = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *lines = [rawWords componentsSeparatedByString:@"\n"];

これは AFNetworking ライブラリを使用しており、さまざまなホスティング事業者からファイルを取得しようとしました。

私は何を間違っていますか?

4

1 に答える 1

2

バンドルに書き込むことはできません (間違いなくデバイス上ではありません。シミュレーターでは可能かもしれません)。ただし、いくつかの事前定義されたディレクトリ (キャッシュ、ドキュメント) に書き込むことができます。StackOverflow に関する次の投稿を確認してください: NSSearchPathForDirectoriesInDomains の説明が混乱している

于 2013-02-11T03:01:23.267 に答える