有道编辑器SDK是有道开放平台提供的云服务之一,是有道编辑器接口的一种实现。拥有多年产品化实践经验,服务于有道云笔记千万用户。
通过SDK接入优势:
开始集成SDK之前开发者需要登录有道开放平台(http://ai.youdao.com),创建应用获取应用ID(或者通过运营人员获取应用ID),以便使用编辑器sdk服务,编辑器SDK只支持iOS 9及以后的系统。
编辑器sdk由如下几个sdk组成:
| 文件 | 说明 | |
|---|---|---|
| Release-iphoneos/editorSDK.framework | 用于真机调试、打包发布的framework | |
| Release-iphonesimulator/editorSDK.framework | 用于模拟器调试的framework | |
| editorSDKSample | sdk使用demo | |
文件目录如下图所示:
编辑器SDK使用的是framework引入方式,需要把对应的editorSDK.framework导入到工程目录下(真机调试、打包发布使用Release-iphoneos/editorSDK.framework,模拟器调试使用Release-iphonesimulator/editorSDK.framework),按如下配置target:
editorSDK.frameworkeditorSDK.frameworkeditorSDK.frameworkeditorSDK.frameworkeditorSDK.framework的所在路径NSAppTransportSecurity 字典并且将 NSAllowsArbitraryLoads 设置为 YES2.1. 初始化key:
所有的编辑器功能都需要初始化key,只执行初始化一次即可。建议用户在AppDelegate.m中的-application:didFinishLaunchingWithOptions:中初始化key。
#import <editorSDK/YNESDKEditorView.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[YNESDKEditorRegister registerWithAppKey:@"zhudytest123" completionBlock:^(BOOL isSuccess, NSError *aError) {
// hander error
}];
return YES;
}
2.2. 初始化编辑器:
在代码中使用时,可用#import <editorSDK/YNESDKEditorView.h>引如sdk,然后就可以新建YNESDKEditorView实例,并使用YNESDKEditorView.h中的- initWithContent: withType:方法初始化,也支持默认初始化和用xib初始化,设置代理之后则可使用YNESDKEditorDelegate中定义的代理接口。
#import <editorSDK/YNESDKEditorView.h>
...
- (void)viewDidLoad {
...
self.editorView = [[YNESDKEditorView alloc] initWithContent:content withType:YNESDKEditorContentTypeXML];
self.editorView.delegate = self;
[self.view addSubview:self.editorView];
}
...
-(void)editorViewClickLinkButton:(YNESDKEditorView *)editorView {
...
[self.editorView insertURL:src];
}2.3 YNESDKEditorView接口
- (instancetype)initWithContent:(NSString *)content withType:(YNESDKEditorContentType)type;- (void) setContent:(NSString*)content withType:(YNESDKEditorContentType)type;- (NSString*)getContentWithType:(YNESDKEditorContentType)type;- (void)insertURL:(NSString*)src;- (void)insertImage:(NSString*)path;+ (NSString*)resourcePath;+ (NSString*)copyToResourcePath:(NSString*)originalPath;- (void)insertAttachmentWithPath:(NSString*)path length:(NSUInteger)length;- (void)updateProgress:(NSInteger)progress ofAttachment:(NSString*)filePath;- (BOOL)canUndo;- (BOOL)canRedo;- (void)undo;- (void)redo;注:接口详情请参考BulbEditor iOS SDK API文档
2.4 YNESDKEditorDelegate代理
-(void)editorView:(YNESDKEditorView *)editorView initIsSuccess:(BOOL)isSuccess withError:(NSError *)error;-(void)editorView:(YNESDKEditorView*)editorView clickImageList:(NSArray*)imageList atIndex:(NSUInteger)index;-(void)editorView:(YNESDKEditorView*)editorView clickAttachment:(NSString*)filePath;-(NSInteger)editorView:(YNESDKEditorView*)editorView getAttachmentInitProgress:(NSString*)filePath;-(void)editorView:(YNESDKEditorView*)editorView clickLink:(NSString*)url;-(void)editorViewClickPhotoButton:(YNESDKEditorView *)editorView;-(void)editorViewClickCameraButton:(YNESDKEditorView *)editorView;-(void)editorViewClickVideoButton:(YNESDKEditorView *)editorView;-(void)editorViewClickLinkButton:(YNESDKEditorView *)editorView;-(void)editorView:(YNESDKEditorView *)editorView undoStatusDidChange:(BOOL)undo;-(void)editorView:(YNESDKEditorView *)editorView redoStatusDidChange:(BOOL)redo;无法使用编辑器
请检查APP_KEY和包名是否匹配。另外,第一次进入APP需要联网校验该APP是否授权,请检查是否联网。
| 错误码 | 含义 |
|---|---|
| 101 | 缺少必填的参数 |
| 102 | 不支持的语言类型 |
| 103 | 请求文本过长 |
| 104 | 不支持的API类型 |
| 105 | 不支持的签名类型 |
| 106 | 不支持的响应类型 |
| 107 | 不支持的传输加密类型 |
| 108 | appKey无效 |
| 109 | batchLog格式不正确 |
| 110 | 无相关服务的有效实例 |
| 111 | 用户无效 |
| 112 | 请求服务无效 |
| 201 | 解密失败 |
| 202 | 签名检验失败 |
| 203 | 访问IP地址不在可访问IP列表 |
| 303 | 服务的异常 |
| 401 | 账户已经欠费停止 |
| 402 | offlinesdk不可用 |
| 404 | 服务访问被禁止,请联系服务提供者 |
| -1 | 网络不可用 |
| 上线日期 | 版本号 | 更新内容 |
|---|---|---|
| 2018.4.26 | v1.0.0 | 有道编辑器SDK iOS版上线,支持富文本编辑 |
| 2018.11.9 | v1.1.0 | 增加纯文本和html格式输出 |