wikitudewikitude-sdk

Wikitude Cordova Plugin - Handle Android and iOS errors


Wikitude Cordova Plugin is used to create our own augmented reality in our cordova based apps. But after adding the plugin and following the official examples the app fails,

Are there any work arounds. How to solve the Android and iOS issues?


Solution

  • Wikitude Cordova Plugin

    Wikitude is an Augmented Reality engine. And Wikitude Cordova Plugin is an Augmented Reality SDK for Cordova to embed augmented reality experiences into your PhoneGap and Cordova based app.

    Note: This document holds good for com.wikitude.phonegap.wikitudeplugin v 6.1.0. Other versions are not tested.

    1. Add the plugin to your app

    Open a console and go to your project directory and run the cordova plugin add command

    $ cordova plugin add https://github.com/Wikitude/wikitude-cordova-plugin.git

    This will add the plugin to your application.

    Run cordova prepare to make the the project ready to build as per config.xml

    2. Enter Wikitude license Key

    Go to License Page and download your personal license key for the Wikitude SDK.

    To use the Wikitude Cordova Plugin with a certain license key, use the this._sdkKey property defined in WikitudePlugin.js line 13.

    plugins\com.wikitude.phonegap.WikitudePlugin\www\WikitudePlugin.js

    3. Android: Handle Wikitude plugin error

    In android, app.wikitudePlugin.isDeviceSupported may fail with the error,

    Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference

    Handle the error by adding a null check to an array in WikitudePlugin.java

    plugins\com.wikitude.phonegap.WikitudePlugin\src\android\WikitudePlugin.java

    line 755: add a null check if(jsonArray != null){} to for (int i = 0; i < jsonArray.length(); i++) {}

    4. Update platforms

    Run the below commands to update the platforms with the changes made in the Wikitude Plugin. It will remove and add the platforms back.

    cordova platform remove android cordova platform add android cordova platform remove ios cordova platform add ios

    5. iOS: Allow CameraUsage

    In iOS, the app may crash with the error,

    This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

    Use PlistBuddy to modify the app's plist file.

    Run the following command from Mac

    $ /usr/libexec/PlistBuddy -c "Add :NSCameraUsageDescription string 'Access to the camera is needed to display augmented reality content on top of your camera image.'" "platforms/ios/"${PROJECT_NAME}"/"${PROJECT_NAME}"-Info.plist"

    Or you can manually add the below entry into platforms/ios/"${PROJECT_NAME}"/"${PROJECT_NAME}"-Info.plist

    NSCameraUsageDescription Access to the camera is needed to display augmented reality content on top of your camera image.

    6. Create your own augmented reality experience

    Steps to Create your own augmented reality experience can be found in Wikitude SDK Cordova documentation.

    Code Examples for what can be done using the Wikitude SDK can be found on GitHub. Also the example Wikitude Cordova Plugin can be found on GitHub.

    For isDeviceSupported function requiredFeatures is optional. But without providing it the App won't work for iOS. So make sure you provide it.

    requiredFeatures: [ "2d_tracking", "geo" ], ... app.wikitudePlugin.isDeviceSupported(app.onDeviceSupported, app.onDeviceNotSupported, app.requiredFeatures);

    7. Build project

    Run the following commands to build the project to specific platforms cordova build android cordova build ios

    For more details on building the apps refer the Cordova documentions, Android Platform Guide and iOS Platform Guide

    Note: #7 is needed for every build. The remaining steps are required only during initial setup.

    Supported devices

    Refer: https://www.wikitude.com/external/doc/documentation/latest/phonegap/supporteddevices.html

    Android device requirements: Supported iOS devices:

    Reference

    Wikitude Cordova Plugin: https://www.wikitude.com/external/doc/documentation/latest/phonegap/

    Note:

    Step#3 solves the Android issue and Step#5 solves the iOS issue.

    Following It’s OK to Ask and Answer Your Own Questions