홈페이지 신용 그렉 간다.
MBProgressHUD를 사용하여 데이터/이미지/파일 다운로드를 시각적으로 표시하고 있습니다.
이제 기존 Dropbox SDK의 DBRestClient 대리자를 제거한 후 이것이 어떻게 작동하는지 확인하는 방법입니다. 내 경우
는, 첫째, 나는 문서 디렉토리에 이미지/파일을 다운로드하고 다음과 같은 코드 -
으로 드롭 박스에서 파일을 나열하고있다.
먼저 파일과 폴더 목록이 필요합니다. 따라서메서드를 호출하여 목록을 가져옵니다. 여기서 경로는 보관 용 계정의 루트입니다.
내 viewDidLoad 메서드에서 목록을 가져 오는 중입니다.
- (void)viewDidLoad
{
[super viewDidLoad];
[self getAllDropboxResourcesFromPath:@"/"];
self.list = [NSMutableArray alloc]init; //I have the list array in my interface file
}
-(void)getAllDropboxResourcesFromPath:(NSString*)path{
DBUserClient *client = [DBClientsManager authorizedClient];
NSMutableArray *dirList = [[NSMutableArray alloc] init];
[[client.filesRoutes listFolder:path]
setResponseBlock:^(DBFILESListFolderResult *response, DBFILESListFolderError *routeError, DBRequestError *networkError) {
if (response) {
NSArray<DBFILESMetadata *> *entries = response.entries;
NSString *cursor = response.cursor;
BOOL hasMore = [response.hasMore boolValue];
[self listAllResources:entries];
if (hasMore){
[self keepListingResources:client cursor:cursor];
}
else {
self.list = dirList;
}
} else {
NSLog(@"%@\n%@\n", routeError, networkError);
}
}];
}
- (void)keepListingResources:(DBUserClient *)client cursor:(NSString *)cursor {
[[client.filesRoutes listFolderContinue:cursor]
setResponseBlock:^(DBFILESListFolderResult *response, DBFILESListFolderContinueError *routeError,
DBRequestError *networkError) {
if (response) {
NSArray<DBFILESMetadata *> *entries = response.entries;
NSString *cursor = response.cursor;
BOOL hasMore = [response.hasMore boolValue];
[self listAllResources:entries];
if (hasMore) {
[self keepListingResources:client cursor:cursor];
}
else {
self.list = dirList;
}
} else {
NSLog(@"%@\n%@\n", routeError, networkError);
}
}];
}
- (void) listAllResources:(NSArray<DBFILESMetadata *> *)entries {
for (DBFILESMetadata *entry in entries) {
[dirList addObject:entry];
}
}
위의 코드 저장 모든 파일과 목록 배열의 DBFILESMetadata
유형의 개체로 폴더.
이제 파일을 다운로드 할 준비가되었지만 파일 크기가 크므로 MBProgressHUD
을 사용중인 다운로드 진행률을 표시해야합니다.
-(void)downloadOnlyImageWithPngFormat:(DBFILESMetadata *)file{
//adding the progress view when download operation will be called
self.progressView = [[MBProgressHUD alloc] initWithWindow:[AppDelegate window]]; //I have an instance of MBProgressHUD in my interface file
[[AppDelegate window] addSubview:self.progressView];
//checking if the content is a file and if it has png extension
if ([file isKindOfClass:[DBFILESFileMetadata class]] && [file.name hasSuffix:@".png"]) {
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* localPath = [documentsPath stringByAppendingPathComponent:file.pathLower];
BOOL exists=[[NSFileManager defaultManager] fileExistsAtPath:localPath];
if(!exists) {
[[NSFileManager defaultManager] createDirectoryAtPath:localPath withIntermediateDirectories:YES attributes:nil error:nil];
}
NSURL *documentUrl = [NSURL fileURLWithPath:localPath];
NsString *remotePath = file.pathLower;
DBUserClient *client = [DBClientsManager authorizedClient];
[[[client.filesRoutes downloadUrl:remotePath overwrite:YES destination:documentUrl] setResponseBlock:^(DBFILESFileMetadata *result, DBFILESDownloadError *routeError, DBRequestError *networkError, NSURL *destination) {
if(result){
NSLog(@"File Downloaded");
}
}] setProgressBlock:^(int64_t bytesDownloaded, int64_t totalBytesDownloaded, int64_t totalBytesExpectedToDownload) {
[self setProgress:[self calculateProgress:totalBytesExpectedToDownload andTotalDownloadedBytes:totalBytesDownloaded]];
}];
}
- (void) setProgress:(CGFloat) progress {
[self.progressView setProgress:progress];
}
- (CGFloat) calculateProgress:(long long)totalbytes andTotalDownloadedBytes:(long long)downloadedBytes{
double result = (double)downloadedBytes/totalbytes;
return result;
}
희망이 있으면 도움이 될 것입니다. 나에게 힌트를 줘서 그렉에게 다시 큰 감사.
감사합니다. 다른 사람들의 hep에서는 MBProgressHUD에 시각적으로 표시 할 백분율로 바이트를 설정하는 방법에 대한 샘플 코드를 추가 할 수 있습니다. 그냥 제안. 고마워. 나는 당신의 제안과 함께 작동시켰다. – Natasha