Downloads images asynchronously and converts them to dcsImage or dcsDocument in DcsBuffer according to the value of mode.


(void) downloadAsync: (DcsHttpDownloadConfig *) config
mode: DcsModeEnum mode
successCallback: (onDownloadSuccess) onSuccess
failureCallback: (onDownloadFailure) onFailure
progressUpdateCallback: (onDownloadProgress) onProgress


config:DcsHttpDownloadConfig Configuration for HTTP download.
mode:DcsModeEnum Indicates if the downloaded files are images or documents.
onSuccess:onDownloadSuccess The callback function when this method performs successfully.
onFailure:onDownloadFailure The callback function when this method performs unsuccessfully.
onProgress:onDownloadProgress The callback function when this method pushes load progress information.

Return value



Circumstance Exception thrown
License verification failed. DcsLicenseVerificationFailedException
Downloaded files are not able to be decoded. DcsDataFormatInvalidException
Download fails due to the network issue. DcsHttpErrorException
No network connection. DcsNetworkDisconnectedException
config is nil or there are errors in data. DcsValueNotValidException
Mode is not DME_DOCUMENT nor DME_IMAGE. DcsValueOutOfRangeException

void (^onDownloadSuccess)()
Description This event is triggered when downloadAsync function is successfully executed.
void (^onDownloadFailure) (DcsException *exception)
Description This event is triggered when saveAsync function is not successfully executed.
Parameter exception: The exception downloadAsync throws.
BOOL (^onDownloadProgress) (NSInteger progress)
Description This event is triggered when downloadAsync function is executing and showing the progress.
Parameter progress: The progress of downloading.
Return When YES is returned, saveAsync will keep executing. When NO is returned, saveAsync will stop.


DcsHttpDownloadConfig *DownloadConfig = [DcsHttpDownloadConfig alloc];
DownloadConfig.url = @"<your download url>"; // Specifies the url of the image you want to download. Please change it to your own.
[ downloadAsync:DownloadConfig mode:DME_IMAGE 
            successCallback:^(NSData* data){NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];NSLog(@"DownloadAsync succeeds! data: %@", str);} 
            failureCallback:^(DcsException *exception){NSLog(@"DownloadAsync fails with exception: %@,%@",, exception.reason);}
            progressUpdateCallback:^BOOL(NSInteger progress){NSLog(@"DownloadAsync on going with %ld percent done", progress);return YES;}];

See also

How to download images/documents from the web

Is this page helpful?

Leave a Reply

Your email address will not be published.