// NewViewController为应用内创建的原生的ViewController类名,所调用页面的内容需要在原生代码中完成
var newVCobj = plus.ios.newObject("NewViewController");
var UIApplicationClass = plus.ios.importClass("UIApplication");
var UIAppObj = UIApplicationClass.sharedApplication();
var del = plus.ios.invoke(UIAppObj,"delegate");
// 如果当前应用delegate对象包含UIWindow对象并且变量名命名为“window”可以这么写,
// 否则需要根据实际代码情况修改
// 应用的delegate对象也可以添加一个返回UIViewController的方法
var appWindowObj = plus.ios.invoke(del,"window");
var appRootController = plus.ios.invoke(appWindowObj,"rootViewController");
plus.ios.invoke(appRootController,"presentViewController:animated:completion:",newVCobj,"YES",null);
var newVCobj = plus.ios.newObject("ViewController");
// 设置其name属性值
newVCobj.plusSetAttribute( "urlString", url );
var UIApplicationClass = plus.ios.importClass("UIApplication");
var UIAppObj = UIApplicationClass.sharedApplication();
var del = plus.ios.invoke(UIAppObj,"delegate");
// 如果当前应用delegate对象包含UIWindow对象并且变量名命名为“window”可以这么写,
// 否则需要根据实际代码情况修改
// 应用的delegate对象也可以添加一个返回UIViewController的方法
var appWindowObj = plus.ios.invoke(del,"window");
var appRootController = plus.ios.invoke(appWindowObj,"rootViewController");
//plus.ios.invoke(appRootController,"presentViewController:animated:completion:",newVCobj,"YES",null);
plus.ios.invoke(appRootController,"pushViewController:animated:",newVCobj,"YES");
1、unipp跳转android界面
jsCallNativeActivity() {
// #ifdef APP-PLUS
//获取宿主上下文
var main = plus.android.runtimeMainActivity();
//通过反射获取Android的Intent对象
var Intent = plus.android.importClass("android.content.Intent");
//通过宿主上下文创建 intent
var intent = new Intent(main.getIntent());
//设置要开启的Activity包类路径 com.example.H5PlusPlugin.MainActivity换掉你自己的界面
intent.setClassName(main, "com.example.H5PlusPlugin.MainActivity");
//开启新的任务栈 (跨进程)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//向原生界面传值操作
intent.putExtra("uni_key", "来自uniapp的值");
//开启新的界面
main.startActivity(intent);
//#endif
}
uniapp接收参数
在onshow方法里面调用
onShow() {
//#ifdef APP-PLUS
if (plus.runtime.arguments) {
let lastAppShare = plus.runtime.arguments;
let appArgs = JSON.parse(lastAppShare);
if (appArgs) {
console.log('receive args from native:', appArgs);
}
}
//#endif
},
2、android打开uniapp指定界面
startActivity(new Intent(this, PandoraEntryActivity.class)
.putExtra("userName", "张三")
.putExtra("token", "TOKEN")
.putExtra("path", "login")
)
android接收参数
Intent i = getIntent();
String uni_key = i.getStringExtra("uni_key");
Toast.makeText(MainActivity.this, uni_key, Toast.LENGTH_LONG).show();
3、AndroidManifest配置