使用服务(Service)
专有钉客户端为开发者提供了一些基础服务,开发者可以通过服务调用专有钉底座能力,服务分为基础服务和业务服务,基础服务包括页面跳转、弹alert(toast)、获取app信息、配置等,业务服务本期暂不提供
服务的调用方式如下
id<DTKXXXServiceProtocol> service = [[DTKXXXServiceInvoker sharedInstance] serviceForProtocol:@protocol(DTKXXXServiceProtocol)];
[service doSomething];
ServiceInvoker中也提供了一些底座服务的便利调用方法,例如
// jump service 的便利调用方法
id<DTKJumpServiceProtocol> jumpService = [[DTKXXXServiceInvoker sharedInstance] jumpService];
[jumpService openURL:@"www.dingtalk.com"];
ConfigurationService
获取交付人员在专有钉集成平台打包时,填入的配置信息,一般为一些随环境变化的配置项,如服务域名等
id<DTKExternalConfigurationServiceProtocol> hostAppService = [[DTKXXXServiceInvoker sharedInstance] configurationService];
[configurationService configForKey:@"hostURL"];
[configurationService boolForKey:@"enabled"];
HostAppService
获取App的基本信息,如展示名称、版本号、scheme、运行环境、租户等
id<DTKExternalHostAppServiceProtocol> hostAppService = [[DTKXXXServiceInvoker sharedInstance] hostAppService];
[hostAppService getHostAppDisplayName]; // 展示名称
[hostAppService currentRuntimeEnvironment]; // 运行环境
JumpService
页面跳转服务,使用时,先注册handler(或viewController)对应的url,再调用openURL
方法跳转至对应页面
// 注册handler
id<DTKJumpServiceProtocol> jumpService = [[DTKXXXServiceInvoker sharedInstance] jumpService];
[jumpService registerHandler:@"XXXViewController" forURL:@"test://xxx/detail"];
// 页面跳转
[jumpService openURL:@"test://xxx/detail"];
LogService
日志服务,将开发者打印的日志打印到专有钉日志系统里,可用于用户主动上传日志排查线上问题(只有正确使用LogService才能落入专有钉日志系统)。
LogLevel:
- Info:info级别日志,可以打一些关键操作路径的日志
- Error:error级别日志,打印错误信息日志
注:打印日志时用户数据需要脱敏,禁止将用户的敏感信息打印到日志服务中id<DTKExternalLogServiceProtocol> logger = [[DTKXXXServiceInvoker sharedInstance] logger];
DTKExternalLogInfo(logger, @"some log"); // info 日志
DTKExternalLogError(logger, @"some error log:", error); // error 日志
请避免日志量过大或打印日志过于频繁
日志格式(其中,1111是bundleId):
// DTKExternalLogInfo(logger, @"some log")
[DTKExt|1111] some log
AlertService\ToastService
用于弹alert、action或toast信息
// alert
id<DTKExternalAlertServiceProtocol> alertService = [[DTKXXXServiceInvoker sharedIntance] alertService];
id<DTKExternalAlertProtocol> alert = [alertService alertWithTitle:@"title" message:nil];
[alert addActionWithTitle:@"OK" style:DTKExternalAlertActionStyleCancel handler:^(){
// do something
}];
[alert showInViewController:someViewController];
// actionsheet
id<DTKExternalAlertServiceProtocol> alertService = [[DTKXXXServiceInvoker sharedIntance] alertService];
id<DTKExternalAlertProtocol> actionSheet = [alertService alertWithTitle:@"title" message:nil style:DTKExternalAlertStyleActionSheet];
[actionSheet addActionWithTitle:@"OK" style:DTKExternalAlertActionStyleCancel handler:^(){
// do something
}];
[actionSheet showInViewController:someViewController];
// toast
id<DTKExternalToastSerivceProtocol> toastService = [[DTKXXXServiceInvoker sharedIntance] toastService];
[toastService showMessage:@"some toast" inView:nil]; // 传nil就在最上层显示
UIHierachyService
用于获取特殊的viewController,如最上层vc、rootViewController等
id<DTKExternalUIHierarchyServiceProtocol> toastService = [[DTKXXXServiceInvoker sharedIntance] uiHierachyService];
[uiHierachyService currentTopViewController]; // 最上层的viewController