使用服务(Service)

专有钉客户端为开发者提供了一些基础服务,开发者可以通过服务调用专有钉底座能力,服务分为基础服务和业务服务,基础服务包括页面跳转、弹alert(toast)、获取app信息、配置等,业务服务本期暂不提供

服务的调用方式如下

  1. id<DTKXXXServiceProtocol> service = [[DTKXXXServiceInvoker sharedInstance] serviceForProtocol:@protocol(DTKXXXServiceProtocol)];
  2. [service doSomething];

ServiceInvoker中也提供了一些底座服务的便利调用方法,例如

  1. // jump service 的便利调用方法
  2. id<DTKJumpServiceProtocol> jumpService = [[DTKXXXServiceInvoker sharedInstance] jumpService];
  3. [jumpService openURL:@"www.dingtalk.com"];

ConfigurationService

获取交付人员在专有钉集成平台打包时,填入的配置信息,一般为一些随环境变化的配置项,如服务域名等

  1. id<DTKExternalConfigurationServiceProtocol> hostAppService = [[DTKXXXServiceInvoker sharedInstance] configurationService];
  2. [configurationService configForKey:@"hostURL"];
  3. [configurationService boolForKey:@"enabled"];

HostAppService

获取App的基本信息,如展示名称、版本号、scheme、运行环境、租户等

  1. id<DTKExternalHostAppServiceProtocol> hostAppService = [[DTKXXXServiceInvoker sharedInstance] hostAppService];
  2. [hostAppService getHostAppDisplayName]; // 展示名称
  3. [hostAppService currentRuntimeEnvironment]; // 运行环境

JumpService

页面跳转服务,使用时,先注册handler(或viewController)对应的url,再调用openURL方法跳转至对应页面

  1. // 注册handler
  2. id<DTKJumpServiceProtocol> jumpService = [[DTKXXXServiceInvoker sharedInstance] jumpService];
  3. [jumpService registerHandler:@"XXXViewController" forURL:@"test://xxx/detail"];
  4. // 页面跳转
  5. [jumpService openURL:@"test://xxx/detail"];

LogService

日志服务,将开发者打印的日志打印到专有钉日志系统里,可用于用户主动上传日志排查线上问题(只有正确使用LogService才能落入专有钉日志系统)。
LogLevel:

  • Info:info级别日志,可以打一些关键操作路径的日志
  • Error:error级别日志,打印错误信息日志
    1. id<DTKExternalLogServiceProtocol> logger = [[DTKXXXServiceInvoker sharedInstance] logger];
    2. DTKExternalLogInfo(logger, @"some log"); // info 日志
    3. DTKExternalLogError(logger, @"some error log:", error); // error 日志
    注:打印日志时用户数据需要脱敏,禁止将用户的敏感信息打印到日志服务中
    请避免日志量过大或打印日志过于频繁

日志格式(其中,1111是bundleId):

  1. // DTKExternalLogInfo(logger, @"some log")
  2. [DTKExt|1111] some log

AlertService\ToastService

用于弹alert、action或toast信息

  1. // alert
  2. id<DTKExternalAlertServiceProtocol> alertService = [[DTKXXXServiceInvoker sharedIntance] alertService];
  3. id<DTKExternalAlertProtocol> alert = [alertService alertWithTitle:@"title" message:nil];
  4. [alert addActionWithTitle:@"OK" style:DTKExternalAlertActionStyleCancel handler:^(){
  5. // do something
  6. }];
  7. [alert showInViewController:someViewController];
  8. // actionsheet
  9. id<DTKExternalAlertServiceProtocol> alertService = [[DTKXXXServiceInvoker sharedIntance] alertService];
  10. id<DTKExternalAlertProtocol> actionSheet = [alertService alertWithTitle:@"title" message:nil style:DTKExternalAlertStyleActionSheet];
  11. [actionSheet addActionWithTitle:@"OK" style:DTKExternalAlertActionStyleCancel handler:^(){
  12. // do something
  13. }];
  14. [actionSheet showInViewController:someViewController];
  15. // toast
  16. id<DTKExternalToastSerivceProtocol> toastService = [[DTKXXXServiceInvoker sharedIntance] toastService];
  17. [toastService showMessage:@"some toast" inView:nil]; // 传nil就在最上层显示

UIHierachyService

用于获取特殊的viewController,如最上层vc、rootViewController等

  1. id<DTKExternalUIHierarchyServiceProtocol> toastService = [[DTKXXXServiceInvoker sharedIntance] uiHierachyService];
  2. [uiHierachyService currentTopViewController]; // 最上层的viewController