title: NativeView description: Starts native view or another app, from a cordova app.
cordova-plugin-nativeview
Start an UIViewController(IOS) or Activity(Android) relative to your cordova app, or an external app (based in cordova plugin startapp cordova plugin)
You can use this in a standalone project (basic cordova project), or into an existing native Android/IOS application, like described in Embed Cordova in native apps
OBS: If you wish just EXIT from cordova app or back to native view (Android only), use:
navigator['app'].exitApp()
Installation
cordova plugin add cordova-plugin-nativeview --save # using IONIC ionic cordova plugin add cordova-plugin-nativeview --save
Extra: Native app (Android/IOS native code)
ALL PLATFORMS
Make sure that config.xml
file contains the <feature>
tag below:
IOS
- Copy the
config.xml
from your cordova project to root XCode project directory. - Install cocoapods
- Add this plugin like a pod dependency:
# Objective-C version (Default) pod 'cordova-plugin-nativeview', '~> 1.0.7' # Swift version (needs update to latest Objective-c implementations) pod 'cordova-plugin-nativeview', :git => 'https://github.com/mfdeveloper/cordova-plugin-nativeview.git', :branch => 'swift'
ANDROID
Add this code snippet below to your build.gradle
file
allprojects { repositories { ... maven { url 'https://jitpack.io' } }} implementation ('com.github.mfdeveloper:cordova-plugin-nativeview:1.0.7')
This dependency is added using jitpack
Or add, the NativeView
class directly to your android project:
-
From your cordova project:
- Copy the content off
platforms/android/assets/www
folder to your android project (usually,app/src/main/assets
). Or create a gradle task to do this. - Copy the
config.xml
tosrc/main/res/xml
android project folder.
- Copy the content off
-
Clone this repo, and copy the class:
src/android/NativeView.java
to your Android project -
Or create a
.jar
or a.aar
that contains this class, and import like a Android module dependency -
Verify if the code snippet below is present in your
AndroidManifest.xml
. This is required to open a specific Activity from a Intent (using [package + activityName])
If this filter not exists in
AndroidManifest.xml
, you will get this error: No Activity found to handle Intent splash screen
- Build/Run your android project!
Supported Platforms
Android
iOS
Methods
NativeView.show(packageOrClassName: string, className: string)
OR
NativeView.show(params: object)
Shows a native view.
ANDROID
document;
IOS
- Pass
Storyboard
name andstoryboard id
document;
- Pass only the
ViewController
class/xib name
/** Or, pass only the UIViewController name, if you don't* use storyboards in your project. This plugin try instantiate* from a ".xib" file. If not exists, try instantiate just by* UIViewController class.* * By convention, your ViewController class/xib needs contains 'Controller' * string in any part of the name * .*/cordovapluginsNativeView; // Preferably, pass the ViewController in a jsoncordovapluginsNativeView;
- Pass only the
Storyboard
name
/** Or, pass only the Storyboard name. If you don't pass a * ViewController class name in second param, the * "rootViewController" of your storyboard will be* instantiated. * * By convention, your Storyboard name needs contains 'Storyboard' * string in any part of the name*/cordovapluginsNativeView; // Preferably, pass the Storyboard in a jsoncordovapluginsNativeView;
NativeView.checkIfAppInstalled(uri: string)
OR
NativeView.checkIfAppInstalled(params: { uri: string })
Verify if another app that responds to a
uri
is installed on device.
cordovapluginsNativeView; // Preferably, pass the uri in a jsoncordovapluginsNativeView;
NativeView.showMarket(marketId: string)
OR
NativeView.showMarket(params: { marketId: string })
Open the store (Apple Store/Google Play) app installed in your device, or in a browser.
ANDROID
// Pass a app package on Android (found this on Google Play)cordovapluginsNativeView; // Preferably, pass the marketId in a jsoncordovapluginsNativeView;
IOS
// Pass a app id from the Apple StorecordovapluginsNativeView; // Preferably, pass the marketId in a jsoncordovapluginsNativeView;
NativeView.getBuildVariant(params: { catchError: boolean })
Get the current Android build variant configured in
ANDROID (ONLY)
/** Pass the param "catchError", and use the `catch()` method to verify an * error (if happens)** Otherwise, this method will return the variant like a string,* or null if not found.** This is useful if you need show a NativeView by environment*/cordovapluginsNativeView; /* Optionally, don't pass any parameter and get the Build Variant * value, or NULL */cordovapluginsNativeView;
IONIC
Replace document.addEventListener
event to this.platform.ready().then(...)
service method. See IONIC Platform documentation
License
This project is licensed under the MIT License - see the LICENSE file for details
TODO
- Better catch IOS exception from JS
- Update
Swift
implementation - Add cordova integration tests