嵌入式小程序——iOS使用指南
嵌入式小程序是百度智能小程序的一种view运行形态,宿主开发者可以在宿主app合适的位置中内嵌该小程序视图,让小程序更好的和宿主app融合在一起。本文介绍了在接入了小程序SDK后,嵌入式小程序的实现流程。
前置条件
嵌入式小程序使用
下面介绍iOS客户端嵌入视图小程序的整体实现流程:
第一步,创建嵌入式小程序承载视图;第二步,加载嵌入式小程序;第三步,同步小程序生命周期;
1. 创建嵌入式小程序承载视图
1 2 3 4 5 6 7 8 9
| // 创建配置信息 BBASMInsetSMAppConfig *config = [[BBASMInsetSMAppConfig alloc] init];
// 根据配置信息创建小程序视图 BBASMInsetSMAppView *smartAppView = [[BBASMInsetSMAppView alloc] initWithFrame:self.testView.bounds parentVC:self configuration:config];
// 添加视图到父视图 [self.testView addSubview:smartAppView];
|
2 加载嵌入式小程序
1 2
| // launchScheme为需要加载小程序的调起协议 [smartAppView loadSMAppWithScheme:launchScheme];
|
3 同步小程序生命周期
1 2 3 4 5
| // 视图可见的时候调用小程序进入前台 [smartAppView appEnterForeground];
// 视图不可见的时候调用小程序进入前台 [smartAppView appEnterBackground];
|