我试图以这种方式从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的工作方式......
答案 0 :(得分: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];
}