正如您所说,OutSystems Now 基于 Cordova,因此您可以轻松地为它创建一个插件,这在整个互联网上都有很好的记录。为了这个答案,假设我创建了一个名为的插件LogoutPlugin
,并且可用的方法是logout
.
至于 webapp 和 OutSystems Now 应用程序之间的通信,你可以尝试以下方法:
- 从 Forge 安装 OutSystems Now - 需要将 OutSystems Now 移动应用程序连接到您的环境。
- 来自 forge 的 Install Now 插件通用 - 需要从 OutSystems Now 应用程序加载 cordova javascript 文件。
现在你可以:
- 在 Service Studio 和您的应用程序中,添加对“Now Plugin common
- 添加对 HTTPRequestHandler/RunJavaScript 的引用
- 创建一个 webblock 并将来自 Now Plugin commons 的 NativePluginLoader 和一个按钮拖入其中。
- 将按钮方法更改为ajax提交并创建一个新的屏幕操作,我称之为“注销”
打开“注销”屏幕操作并将 RunJavaScript 操作拖入其中。这将是我们调用我们想要的cordova插件的地方!因为,在这个答案的开头,我说我创建了 LogoutPlugin,我们可以这样称呼它:
cordova.exec(function(){console.log("success");}, function(e){console.log("fail" + e);}, "LogoutPlugin", "logOut", []);
在本机端,例如对于 Android,插件类看起来像下面这样:
public class LogoutPlugin extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
if (action.equals("logout"))
logout();
return true;
}
private void logout() {
cordova.getActivity().finish();
}
}
注意:cordova
仅当您在 OutSystems Now 中运行 webapp 时才可用,否则NativePluginLoader
将无法从设备加载 cordova.js 文件。
为了进一步学习,您可以查看 OutSystems github repos,您可以在其中找到一些 OutSystems Now 的插件。
希望这会让你继续前进,而且,这里有一个 oml 作为例子