File Sharing
  • Platform
  • Framework / Engine
  • iOS
  • Android
  • macOS
  • Windows
  • Linux
  • Web
  • WeChat Mini Program

Function Realization

Update Time:2021-04-25 20:24

1 Function Introduction

After the SDK is integrated, if you want to use the functions of the SDK, you need to create the file instance object DocView after the SDK is initialized, and then further call the various APIs provided by ZegoExpressDocs.

2 Initialize the SDK

Before initialization, you need to apply for AppID and AppSign. When you initialize, you need to specify the log, data, and cache path, and set the operating environment.

ZegoDocsViewConfig * config = [ZegoDocsViewConfig new];
config.appSign = appSign; //AppSign applied for
config.appID = appID;//AppID applied for
config.dataFolder = kZegoAppDCDataPath;//SDK related data directory
config.isTestEnv = YES; //Test environment, set according to the applied appid
config.cacheFolder = [ZegoTools cachePath];//SDK related cache directory
config.logFolder = kZegoAppDCDataPath;//SDK related log directory

[[ZegoDocsViewManager sharedInstance] initWithConfig:config completionBlock:^(ZegoDocsViewError errorCode) {
    if (errorCode == ZegoDocsViewSuccess) {
        NSLog(@"SDK initialization successful");
    } else {
        NSLog(@"SDK initialization failed %ld",errorCode);
    }
}];

3 Uninitialize the SDK

Call the uninit method to uninitialize the SDK.

[[ZegoDocsViewManager sharedInstance] uninit];

4 Upload File

Call the upload method to upload file to the server. File uploads are divided into uploading ZegoDocsViewUploadStateUpload and format conversion ZegoDocsViewUploadStateConvert Two stages.

  • Upload stage: If the upload is normal, multiple callbacks will be generated, each time including the file upload progress. For example, if the current upload is 50%, the infoMap content is {"upload_percent":@(0.50)}; if the current upload is 100%, the infoDictionary content is {"upload_percent":@(1.00)}. Currently uploading 100%, the infoDictionary content is {"upload_percent":@(1.00)}.
  • Format conversion stage: If the conversion is successful, only one callback will be generated, including the converted file ID. For example, the current conversion is completed, the content of the infoDictionary is {"upload_fileid":"ekxxxxxxxxv"}.
//The absolute path of the file, which can be obtained according to the iOS API
//The rendering mode type after uploading the file after transcoding, the default is ZegoDocsViewRenderTypeVector format
[[ZegoDocsViewManager sharedInstance] uploadFile:[url path] renderType:ZegoDocsViewRenderTypeVector completionBlock:^(ZegoDocsViewUploadState state, ZegoDocsViewError errorCode, NSDictionary * _Nonnull infoDictionary) {
    if (errorCode == ZegoDocsViewSuccess) {
        if (state == ZegoDocsViewUploadStateUpload) {
            // uploading...
            if(upload_percent.intValue == 1){
                // Transcoding...
            }
        } else if (state == ZegoDocsViewUploadStateConvert){
            // successful conversion
        }
    } else {
        // upload failed
    }
}];

5 Load File

  1. This method may require file transcoding permission. If you encounter loading failure, please check the error code document first. The possible failure scenarios are as follows:
  • No permission required for transcoding of loaded file.
  • AppID & AppSign do not match the transcoding of the file to be loaded.
  • File transcoding is in the official environment and the initialized SDK is in the test environment.
  1. Currently DocsView has called loadFileWithFileID after the interface loads the file, you need to call unloadFile interface to unload the file before it can be used again loadFileWithFileID Load file.

  2. Only before calling loadFileWithFileID interface, and then the reload interface can be called.

// 1. init
self.docView = [[ZegoDocsView alloc] init]; //Initialize file View
self.docView.backgroundColor = UIColor.whiteColor; //Set the background color of the file View
[self.docView setDelegate:self]; //Set file View proxy notification
[self.view addSubview:self.docView]; //Add to the View you need to display

//2. Set the size of the visible area
self.docView.frame = CGRectMake(0, 0, 100, 100);

//3. Load file
[self.docView loadFileWithFileID:@"fileID" //Get the file ID in the background
                         authKey:@"" //Authentication key. Can be empty. Fill in according to whether the environment you are applying for requires authentication. It is best to get it through the background
                 completionBlock:^(ZegoDocsViewError errorCode) {

}];

If you want to achieve the function of drawing on file and multi-terminal linkage, you need to introduce the interactive whiteboard function. For details, please refer to ZegoDocsView SDK.

6 Scroll to Page

Call flipPage to flip the file.

  1. Scrolling page has made two external interfaces for dynamic PPT and non-dynamic PPT.
  2. Both the jump page and current page steps start with 1.
// Example: Non-dynamic PPT jumps to page 3.
[self.docView flipPage:3 completionBlock:^(BOOL isScrollSuccess) {
    NSLog(@"End of page turning");
}];

// Example: Dynamic PPT jump to page 2, step 4.
[self.docView flipPage:2 step:4 completionBlock:^(BOOL isScrollSuccess) {
    NSLog(@"End of page turning");
}];

7 File Zoom

Call scaleDocsView to zoom the file.

  1. File scaling needs to specify the scaling factor scaleFactor, which is the scale factor for reducing or enlarging.
  2. ScaleOffset represents the left starting point of the area that needs to be displayed after zooming in or out.
[self.docsView scaleDocsViewWithScaleFactor:scaleFactor scaleOffsetX:scaleOffsetX scaleOffsetY:scaleOffsetY];

8 Get File Thumbnail

Call getThumbnailUrlList to get file thumbnails.

  1. Get the current file thumbnail list, only supports PDF, PPT, dynamic PPT file formats.
  2. It needs to be called after the file is loaded successfully.
NSArray *thumbnailUrls = [self.docsView getThumbnailUrlList];

9 Excel File Switching Sheet

If there are many sheet pages in the Excel file, you can use the following interface to switch between sheet pages. Sheet subscript, starting from 0.

[self.docView switchSheet:0];

10 Dynamic PPT Operation

Each page of dynamic PPT (ie the file type is ZegoDocsViewFileTypeDynamicPPTH5) may have many steps, which can be passed through nextStepWithCompletionBlock and previousStepWithCompletionBlock method for the previous and next steps of dynamic PPT.

//Previous
[self.docViewFirst previousStepWithCompletionBlock:^(BOOL isScrollSuccess) {

}];
//Next
[self.docViewFirst nextStepWithCompletionBlock:^(BOOL isScrollSuccess) {

}];