1

私はこの方法でDropboxからいくつかの画像をダウンロードしようとしています:

-(void)catchTheImage{

NSString *title = [[NSUserDefaults standardUserDefaults]objectForKey:@"Folder3"];
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
NSString *filename2 = [NSString stringWithFormat:@"/%@photofile.png.%ld", title, (long)sharedSingleton.tagNumber];

NSString *tmpPngFile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", filename2]];

[restClient loadFile:filename2 intoPath:tmpPngFile];

[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(lf) userInfo:nil repeats:NO];

}

-(void)lf{

NSString *tmpPngFile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", filename2]];
UIImage* image = [UIImage imageWithContentsOfFile:tmpPngFile];
photoView.image = image;
}

タイマーは良い考えではありませんが、試してみるだけです。ドロップボックスの画像は3であるため、TagNumberは1、2、または3になりますが、画像は表示されません。フォルダにはまったく保存されていないと思います。NSTemporaryDirectoryがどのように機能するかについて誤解している可能性があります...

4

1 に答える 1

3

はい、読み込みプロセスに関するステータスを返すDropboxデリゲートメソッドを実装する必要があります

ここにあります

- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath;
// Implement the following callback instead of the previous if you care about the value of the
// Content-Type HTTP header and the file metadata. Only one will be called per successful response.
- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath contentType:(NSString*)contentType metadata:(DBMetadata*)metadata;
- (void)restClient:(DBRestClient*)client loadProgress:(CGFloat)progress forFile:(NSString*)destPath;
- (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error;

そしてあなたの場合:

- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath contentType:(NSString*)contentType metadata:(DBMetadata*)metadata {

NSString *tmpPngFile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", filename2]];
UIImage* image = [UIImage imageWithContentsOfFile:tmpPngFile];
photoView.image = image;

}


- (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error {

    [[[UIAlertView alloc] initWithTitle:@"Oops!!!" message:@"Try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] show];
}
于 2012-12-08T09:17:28.473 に答える