0

さて、私のアプリでは、ダウンロードする必要があるいくつかの画像の URL を含む json オブジェクトを取得しています。以下のコードですべてを行います。画像はダウンロードされ、作成したディレクトリに保存されます。つまり、ファイルはそこにあり、オーガナイザーを使用してそれらを見ることができます。何をしても、アプリを再度起動するまでfilemanagerには表示されません。nsfilemanager のリフレッシュ機能はありますか?

- (void)updateResizeableAssets{
NSString* tempDirectory = NSTemporaryDirectory();
tempDirectory = [tempDirectory stringByAppendingString:@"Assets/"];
if(![[NSFileManager defaultManager] fileExistsAtPath:tempDirectory isDirectory:nil])
{
    [[NSFileManager defaultManager] createDirectoryAtPath:tempDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}

NSURLRequest *requestResizeable = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://someurl.com/"]];
[NSURLConnection sendAsynchronousRequest:requestResizeable queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData* data, NSError *connectionError){
    NSError *jsonParsingError = nil;
    NSDictionary *arrayOfImages;
    NSArray *object = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonParsingError];
    for(int i=0; i<[object count];i++)
    {
        arrayOfImages= [object objectAtIndex:i];
        NSString *imageStringUrl = @"http://someotherurl.com/";
        imageStringUrl = [imageStringUrl stringByAppendingString:(NSString*)[arrayOfImages objectForKey:@"name"]];
        NSURLRequest *imageUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:imageStringUrl]];

        if(![[NSFileManager defaultManager] fileExistsAtPath:[tempDirectory stringByAppendingString:[arrayOfImages objectForKey:@"name"]]])
        {
            [NSURLConnection sendAsynchronousRequest:imageUrl queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData* data, NSError *connectionError){
                [[NSFileManager defaultManager] createFileAtPath:[tempDirectory stringByAppendingString:[arrayOfImages objectForKey:@"name"]] contents:data attributes:Nil];

            }];
        }
        //NSLog(@"Image: %@", [arrayOfImages objectForKey:@"name"]);
    }

    NSString* tempDirectory = NSTemporaryDirectory();
    tempDirectory = [tempDirectory stringByAppendingString:@"Assets/"];
    NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tempDirectory error:nil];
    for(int i=0; i<[files count]; i++)
    {
        //HERE I GOT NOTHING UNTIL I RESTART THE APP (Run App twice)
        NSLog(@"%@", [files objectAtIndex:i]);
    }
}];

}

4

1 に答える 1