ZEGOCLOUD no longer classifies environments into production environments and testing environments.
If you create your project in ZEGOCLOUD Admin Console on/before 2021-11-16, refer to the Testing environment deprecation to upgrade the SDK and adjust related codes.
Create a project in the ZEGO Admin Console and apply for a valid AppID and AppSign. For details, please refer to the Console - Project Management.
Integrate ZegoDocsView SDK into the project. For details, please refer to Quick Starts- Integration.
2.3.0 or later
, you can also use Tokens for authentication. To upgrade the authentication mode, refer to the Upgrade the authentication mode from AppSign to Token.This section is divided into four parts to introduce the ZegoDocsView SDK:
If you want to realize the function of drawing on files and multi-terminal linkage, you need to introduce the Collaborative Whiteboard function. For details, please refer to ZegoWhiteboardView SDK.
// Introduce ZegoDocsView SDK header files
#import <ZegoDocsView/ZegoDocsView.h>
When initializing the SDK, you need to set the log file save path, the SDK internal data file save path, the file cache path, and the operating environment.
The operating environment parameters need to be consistent with the corresponding environment when applying for AppID.
ZegoDocsViewConfig *config = [ZegoDocsViewConfig new];
config.appSign = appSign; //That is, AppSign
config.appID = appID;//that is, AppID
config.dataFolder = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/ZegoDocs"] stringByAppendingString:@"data"];//SDK Related data catalog
config.cacheFolder = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/ZegoDocs"] stringByAppendingString:@"doc"];//SDK Related cache directory
config.logFolder = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/ZegoDocs"] stringByAppendingString:@"log"];//SDK Related log directory
[[ZegoDocsViewManager sharedInstance] initWithConfig:config completionBlock:^(ZegoDocsViewError errorCode) {
if (errorCode == ZegoDocsViewSuccess) {
NSLog(@"Successfully initialized SDK");
} else {
NSLog(@"Failed to initialize SDK %ld",errorCode);
}
}];
Call the upload file method of ZegoDocsViewManager to upload the file to the ZEGO file cloud service. After the upload is successful, the fileID of the file will be obtained, and the developer can call ZegoDocsView LoadFileWithFileID interface, input fileID to load the file.
The uploaded file must meet the corresponding specifications:
Please use Microsoft Office 2013 or above to edit/save the file. Files saved in earlier versions of Microsoft Office or other office software, such as WPS, Keynote, Microsoft Office 2003, etc., are not supported.
The file must be editable and does not support "read-only", "encrypted", or other protected documents, otherwise the transcoding will fail.
For all specifications, please refer to Overview - File Specification.
File upload is divided into two stages: upload ZegoDocsViewUploadStateUpload and format conversion ZegoDocsViewUploadStateConvert.
{"upload_percent":@(0.50)}
; if the current upload is 100%, the content of "infoDictionary" is {"upload_percent":@(1.00)}
.{"upload_fileid":"ekxxxxxxxxv"}
. The corresponding value of upload_fileid is the file fileID.Call the uploadFile method to upload ordinary files.
//filePath The absolute path of the file to be uploaded can be obtained using the iOS system API.
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
//The rendering mode type after uploading the file after transcoding, the default is ZegoDocsViewRenderTypeVector format, if the user is involved in the business of iOS, Web, Windows, Mac, and applets, it is recommended to use ZegoDocsViewRenderTypeVectorAndIMG mode.
ZegoDocsViewRenderType renderType = ZegoDocsViewRenderTypeVectorAndIMG;
[[ZegoDocsViewManager sharedInstance] uploadFile:filePath renderType:renderType completionBlock:^(ZegoDocsViewUploadState state, ZegoDocsViewError errorCode, NSDictionary * _Nonnull infoDictionary) {
if (errorCode == ZegoDocsViewSuccess) {
if (state == ZegoDocsViewUploadStateUpload) {
// uploading...
NSString *uploadPercent = infoDictionary[@"upload_percent"];
if(uploadPercent.intValue == 1){
// Transcoding...
}
} else if (state == ZegoDocsViewUploadStateConvert){
// The conversion is successful, the file ID is obtained, and the fileID can be obtained through the "upload_fileid" key
// You can call ZegoDocsView's loadFile interface and pass in the fileID to load the file.
NSString *fileID = infoDictionary[@"upload_fileid"];
/* Uploaded successfully
[self.zegoDocsView loadFileWithFileID:fileID authKey:nil completionBlock:^(ZegoDocsViewError errorCode) {
NSLog(@"%d", errorCode);
}];
*/
}
} else {
// upload failed
}
}];
Set the configuration parameters of uploading H5 files through ZegoDocsViewCustomH5Config, and call the uploadH5File method to upload H5 files.
//The absolute path of the file, which can be obtained according to the iOS API
[[ZegoDocsViewManager sharedInstance] uploadH5File:[url path] config:config 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
}
}];
Create ZegoDocsView and add it to the view.
// 1. init
self.docView = [[ZegoDocsView alloc] init]; //Initialization 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 frame
self.docView.frame = CGRectMake(0, 0, 100, 100);
Call the loadFileWithFileID interface of ZegoDocsView, and pass in the fileID load file obtained after the upload is successful.
// fileID Get after uploadFile succeeds
NSString *fileID = @"";
[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) {
}];
After the current DocsView has called the loadFileWithFileID interface to load the file, you need to call the unloadFile interface to unload the file before you can use the loadFileWithFileID to load the file again.
The loadFileWithFileID interface can only be called before, and then the reloadFileWithCompletionBlock interface can be called.
// Example: Non-dynamic PPT Jump 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");
}];
After the file is loaded successfully, you can call scaleDocsViewWithScaleFactor to zoom the file.
[self.docsView scaleDocsViewWithScaleFactor:scaleFactor scaleOffsetX:scaleOffsetX scaleOffsetY:scaleOffsetY];
After the file is loaded successfully, you can call getThumbnailUrlList to get the file thumbnail.
NSArray *thumbnailUrls = [self.docsView getThumbnailUrlList];
If the file uploaded by the developer is an Excel file and there are multiple sheet pages, you can use the switchSheet method to switch the sheet pages, and the sheet pages start from 0.
[self.docView switchSheet:0];
Dynamic PPT, that is, a file whose file type is "ZegoDocsViewFileTypeDynamicPPTH5", this type of file may have multiple steps per page.
If the file uploaded by the developer is a dynamic PPT file, you can use the nextStepWithCompletionBlock and previousStepWithCompletionBlock methods to perform the previous and next steps of the dynamic PPT, and perform the dynamic PPT jump up and down turn. The operation of dynamic PPT can only be called after the file is loaded.
//Previous
[self.docViewFirst previousStepWithCompletionBlock:^(BOOL isScrollSuccess) {
}];
//Next
[self.docViewFirst nextStepWithCompletionBlock:^(BOOL isScrollSuccess) {
}];
Developers can experience the File Sharing business in the File Sharing sample project, and view the complete source code and code logic. For details, please refer to File Sharing - Sample Codes.