EMAS支持Native App接入WindVane小程序容器和uni-app小程序容器,您可根据业务需要,选择接入的小程序容器类型。本文介绍iOS端接入小程序容器的详细操作。
前提条件
已获取Native App的AccessKey、SecretKey和App Code,获取方式请参见用户指南的应用开放平台(平台运营方) > 设置App章节。
已获取应用开放平台的环境域名。体验环境域名为:
poc.superapp-intl.com。
步骤一、添加依赖
添加部署的CocoaPods仓库
pod repo add superapp-intl-emas-ios-emas-specs https://gitlab-console.superapp-intl.com/emas-ios/emas-specs.git pod repo add superapp-intl-emas-ios-emas-specs-thirdpart https://gitlab-console.superapp-intl.com/emas-ios/emas-specs-thirdpart.git在工程根目录的
Podfile中,配置CocoaPods仓库。小程序容器相关SDK发布在部署的CocoaPods仓库上,账户密码可以联系运维工程师提供。
source 'https://gitlab-console.superapp-intl.com/emas-ios/emas-specs.git' source 'https://gitlab-console.superapp-intl.com/emas-ios/emas-specs-thirdpart.git'在工程根目录的
Podfile中,添加小程序容器的依赖。use_frameworks! //小程序容器基础sdk,必须集成 pod 'EMASServiceManager' pod 'EMASMiniAppAdapter' //WindVane小程序容器,如果选择WindVane小程序,则需要集成。 pod 'EMASWindVaneMiniApp' //uni-app小程序容器,如果选择uni-app小程序,则需要集成。 pod 'EMASUniappMiniApp'
步骤二、初始化容器
使用小程序容器前,需要初始化小程序容器。
// 初始化SDK
EMASMiniAppInitConfig *miniAppInitConfig = [EMASMiniAppInitConfig new];
miniAppInitConfig.useUniApp = YES;
miniAppInitConfig.useWindVane = YES;
miniAppInitConfig.accessKey = @"ZXZ8****";//从应用开放平台获取
miniAppInitConfig.secretKey = @"3PNJxKtf7/eqUohlG3bI****";//从应用开放平台获取
miniAppInitConfig.host = @"emas.example.com";//请配置您的环境域名,此处仅为示例。体验环境域名为:emas-publish-intl.emas-poc.com。
miniAppInitConfig.appCode = @"161160615860445224****";//从应用开放平台获取
EMASMiniAppServiceImpl *miniAppService = [EMASMiniAppServiceImpl new];
[miniAppService initialize:miniAppInitConfig];
[[EMASServiceManager sharedInstance] registerServiceProtocol:@"EMASMiniAppService" IMPClass:@"EMASMiniAppServiceImpl" target:miniAppService];
//下面是WindVane小程序容器的其他配置。若使用需要实现对应类。
//[[EMASServiceManager sharedInstance] registerServiceProtocol:@"EMASMiniAppFavoriteService" IMPClass:@"EMASMiniAppFavoriteServiceImpl" target:[EMASMiniAppFavoriteService new]];//收藏功能
//[[EMASServiceManager sharedInstance] registerServiceProtocol:@"EMASUserInfoService" IMPClass:@"EMASUserInfoServiceImpl" target:[EMASUserInfoServiceImpl new]];//关联用户功能
//[[EMASServiceManager sharedInstance] registerServiceProtocol:@"EMASMiniAppURLService" IMPClass:@"EMASMiniAppURLServiceImpl" target:[EMASMiniAppURLServiceImpl new]];// 拦截URL功能注意事项
使用Apple Silicon M系列芯片的Mac电脑并使用模拟器运行时,模拟器需要选择Rosetta标识的模拟器。
安装Rosetta,终端运行以下代码:
sudo softwareupdate --install-rosetta --agree-to-license未使用Rosetta运行报错Building for 'iOS-simulator',but linking in object file, 需要修改 Build Settings -> Excluded Architectures 选项,添加Any iOS Simulator SDK选项,设置值为arm64。三方库报错x86_64 Undefined symbol:_OBJC_CLASS_$_ ,需要在工程的 build setting -> Other linker flags中添加 -ld64,之后在Product -> Destination 选择Rosetta标识的模拟器运行项目。
在 Xcode15新增ENABLE_USER_SCRIPT_SANDBOXING,遇到报错Sandbox: rsync.samba deny 修改build setting -> user script sandboxing 为No。
API参考
关于API的详细说明请参见API参考。