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;
}

我知道计时器不是一个好主意,但它只是为了尝试。TagNumber 可以是 1、2 或 3,因为 Dropbox 上的图像是 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 回答