This is a React Native bridge module for Wikitude which provides a simple integration to the Wikitude AR SDK.
First install the module via npm and link it up:
npm install joaquinlom/react-native-wikitude-sdk
react-native link react-native-wikitude-sdk
After that completes, you will need to do additional steps for each platform you are supporting:
-
Unfortunately the gradle system does not seem to allow sub-linking aar files. To get around this you will have to install the
wikitudesdk
folder manually into each project you plan to use this module with.Copy the
wikitudesdk
folder from thenode-modules/react-native-wikitude/android
folder into your project'sandroid
folder:On Mac / Linux:
cd YourReactNativeProject cp -R ./node_modules/react-native-wikitude/android/wikitudesdk ./android/wikitudesdk
or on Windows:
cd YourReactNativeProject xcopy node_modules\react-native-wikitude\android\wikitudesdk android\wikitudesdk /E
-
And then in your
android/settings.gradle
file, modify the existinginclude ':react-native-wikitude'
line to also include thewikitudesdk
:include ':wikitudesdk',':react-native-wikitude-sdk'
project(':react-native-wikitude-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wikitude-sdk/android') ```
-
In your
android/build.gradle
file, modify the minimum SDK version to at least version 19:android { defaultConfig { ... minSdkVersion 21 ... }
-
In your
android/app/src/main/AndroidManifest.xml
file, If you have it, remove theandroid:allowBackup="false"
attribute from theapplication
node. If you want to set allowBackup, follow the method here. -
Optionally: In your
android/build.gradle
file, define the versions of the standard libraries you'd like WikitudeBridge to use:... ext { // dependency versions compileSdkVersion = "<Your compile SDK version>" // default: 27 buildToolsVersion = "<Your build tools version>" // default: "27.0.3" targetSdkVersion = "<Your target SDK version>" // default: 27 constraintLayoutVersion = "<Your com.android.support.constraint:constraint-layout version>" //default "1.0.2" } ...
after install the package, you need to run 'pod install' inside ios folder
cd ios
pod install
make sure that the WikitudeSDK is inside node_modules/react-native-wikitude-sdk/ios
https://stackoverflow.com/questions/24993752/os-x-framework-library-not-loaded-image-not-found
You can only have one feature enable, the default is all. To change the feature you will need to destroy and recreate the component.
if you have a memory leak or a crash because you switch screens, you need to tell Wikitude to Stop rendering , to do this you will need to ref the component and call
wikitudeRef.current.stopRendering() and wikitudeRef.current.resumeRendering()
You can run wikitude with local experiences, in order to do this, you will need to handle different betweens platforms
Go to you main project android folder /android/app/src/main ; Create a new folder called assets, inside here you will put your folder with your experiences.
and to use it, just put the typescript url property
to your index file (Without the extension).
Example:
url: 'ARchitectExamples/07_3dModels_4_SnapToScreen/index'
Open your xworkspace file , and link a file inside the main folder.(You can drag & drop the file into xcode) You need to check that the assets are in the Build phase - Copy Bundle resources. Example: url: 'assets/ARchitectExamples/07_3dModels_4_SnapToScreen/index' P.D- this is also whitout the extension.
On Android, the assets folder naming is no neccessary but it does on IOS, you can do a conditional to set the url
Just put the url in the property, it's need to be a public URL.
<WikitudeView
ref="wikitudeView"
style={{ flex: 1 }}
url={arCloud}
licenseKey={licenseKey}
feature={WikitudeView.Geo}
onJsonReceived={this.onJsonReceived}
onFinishLoading={this.onFinishLoading}
onScreenCaptured={this.onScreenCaptured}
/>
Wikitude needs the camera for display AR.
will ask for permission using the PermissionsAndroid module from React Native. if no permissions was granted, it will render a button to ask again.
Please verify the info.plist for the camera permission text, the module only check the camera permission. Note- If the users grant permission but goes to the settings and change the permission, it wont ask again for the permission, you need to link the user to the settings page or display a message.
-
setWorldUrl(url) Set the URL to load into the Wikitude View
-
callJavascript(str) Send a String as a JS, to inject into the ARView and call it.
-
injectLocation(lat,ln) Send location into the view to inject the location of the device, TODO
-
stopRendering Stops all rendering of the Wikitude View, this will stops the camera also
-
resumeRendering Resume the current experience, you need to stop first in order to resume.
-
captureScreen Will take a screenshot and the onScreenCapture will fired with a Base64 image inside the image property (event.image)
-
onJsonReceived(event) handles the JSON received event from the Experience
-
onFinishLoading(event) on Android it might call twice when is a online experience. handles the event when the Experience is finish loading
-
onFailLoading(event) handles the event when the experinces has an error loading
-
onScreeCaptured(event) handles when the images is taken, will have a Image property that is a Base64 String.
You can check this example app Github.
- Rigth now, it only had Camera permission, if you need something else you will need to do it mannually
- This is work in progress, it's not ready for production, use it as you own risk.
- 1.0.0 First Commit