BaseApplication

最低版本: 2.0.0最后更新: 2021/2/3

OPK 入口组件基类,封装了基本的路由处理功能,和对 deeplink 的拦截和处理功能。

支持平台:

 

 

平台是否支持
豹小秘
豹大/花瓶
豹小秘 Mini

 

方法

方法名参数JS类型必填参数说明方法说明最低版本
onTriggerByIFTTTecaInfoECAGroupRulesyesifttt 启动信息当opk被ifttt类型的deeplink触发时,该方法会被回调2.0.0
registerDeepLinkInterceptorinterceptorDeepLinkInterceptoryesdeep link拦截器注册deep link的拦截器2.0.0
afterStartByDeepLinkpathstringyes要切换到的path冷启动2.0.0
queryanyyes启动 opk 指令信息
afterRecoveryByDeepLinkpathstringyes要切换到的path从suspend切到运行状态2.0.0
queryanyyes恢复 opk 指令信息
afterNewDeepLinkpathstringyes要切换到的pathOPK 在前台的时候,收到DeepLink2.0.0
queryanyyes指令信息
notifyUpdateActiveAbilityMini toC 上用于通知 global 更新主动能力,默认是启用所有主动能力,业务方可重新该方法执行不同的逻辑2.0.0

代码示例

@observer
class App extends BaseApplication<BaseApplicationProps> {

   public constructor(props: any) {
       super(props);
       this.initDeepLink();
   }

   private initDeepLink(): void {
       const handleDeepLink = (path: string, query: any = {}): boolean => {
           console.log(TAG, 'query:' + JSON.stringify(query));
           if (path === '/alarmlist') {
               speechApi.queryByText('查看闹钟');
               return true;
           } else if (path === '/follow') {
               if (!ActiveAbilityController.isBodyFollowEnable()) {
                   ActiveAbilityController.setBodyFollowEnable(true);
               }
               return true;
           } else if (query.asrShow !== undefined) {
               if (query.asrShow === 'false') {
                   globalASRModel.setVisible(false);
               }
               return true;
           }
           return false;
       };
       const skillInterceptor: DeepLinkInterceptor = {
           intercept(path: string, query: any): OpenDeepLinkInfo | undefined {
               if (handleDeepLink(path, query)) {
                   return undefined;
               } else {
                   return { path, query };
               }
           }
       };
       this.registerDeepLinkInterceptor(skillInterceptor);
   }

   public componentWillMount(): void {
       console.log(TAG, 'componentWillMount');
   }

   public componentDidMount(): void {
       super.componentDidMount();
       console.log(
           TAG,
           'componentDidMount'
       );
   }

   public componentWillUnmount(): void {
       super.componentWillUnmount();
       console.log(TAG, 'componentWillUnmount');
   }

   public render(): React.ReactElement {
       return (
           <View style={styles.container}>
               <ViewContainerProvider />
               <AppContainer />
           </View>
       );
   }

 

   // 禁用主动能力
   public notifyUpdateActiveAbility() {
       ActiveAbilityManager.disableAll();
   }
 

}