DCUniMPMenuActionSheetItem *item1 = [[DCUniMPMenuActionSheetItem alloc] initWithTitle:@"重启" identifier:@"item1"]
// 添加到全局配置
[DCUniMPSDKEngine setDefaultMenuItems:@[]];
// 设置 delegate
[DCUniMPSDKEngine setDelegate:self];
// 启动 uni小程序,(参数可以在小程序中通过 plus.runtime.arguments 获取此参数)
NSMutableDictionary *arguments = [NSMutableDictionary dictionary];
DCUniMPConfiguration *config = [DCUniMPConfiguration new];
config.arguments = arguments;
config.redirectPath = self.uniAppPath;
self.uniAppPath = nil;
config.enableBackground = NO;
[DCUniMPSDKEngine preloadUniMP:packName configuration:config completed:^(DCUniMPInstance * _Nullable uniMPInstance, NSError * _Nullable error) {
if (uniMPInstance) {
// 预加载后打开小程序
[uniMPInstance showWithCompletion:^(BOOL success, NSError * _Nullable error) {
if (error) {
NSLog(@"show 小程序失败:%@",error);
TOASTOFSTRING(kQMLocalStr(@"打开小程序失败"));
}
}];
} else {
[self.topController.view hideToastActivity];
NSLog(@"预加载小程序出错:%@",error);
}
}];
/// 小程序关闭回调方法
- (void)uniMPOnClose:(NSString *)appid {
self.uniMpInstance = nil;
NSLog(@"小程序 %@ 被关闭了",appid);
}
0 个回复