joaquinlom / react-native-wikitude-sdk

Wikitude SDK to React Native
http://spinarplus.com
12 stars 14 forks source link

React Native Wikitude Bridge

Introduction

This is a React Native bridge module for Wikitude which provides a simple integration to the Wikitude AR SDK.

How to install

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:

Android

  1. Wikitude since 8.9 can be added via Maven, so in order to include it into your proyect you need to add the maven repository in your android/build.gradle

        repositories{
             maven {
                url 'https://cdn.wikitude.com/sdk/maven'
            }
        }
    
        allprojects{
             maven {
                url 'https://cdn.wikitude.com/sdk/maven'
            }
        }
  2. This Library uses Wikitude Version 9.6, but if you need to modify the Version, go to the node_modules/react-native-wikitude-sdk/android/build.gradle

    dependencies{
        implementation 'com.wikitude:js:9.6.0'
    }
  3. In your android/app/src/main/AndroidManifest.xml file, If you have it, remove the android:allowBackup="false" attribute from the application node. If you want to set allowBackup, follow the method here.

  4. If you are upgrading from the last version, you will need to remove the preivious setup.

    • remove the reference to wikitudesdk in the settings.gradle
    • and remove the lib reference from android/app/build.gradle

iOS

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

Usage

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()

Offline Experiences

You can run wikitude with local experiences, in order to do this, you will need to handle different betweens platforms

Android

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'

IOS

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.

Considerations

On Android, the assets folder naming is no neccessary but it does on IOS, you can do a conditional to set the url

Online

Just put the url in the property, it's need to be a public URL.

Render

<WikitudeView
        ref="wikitudeView"
        style={{ flex: 1 }}
        url={arCloud}
        licenseKey={licenseKey}
        feature={WikitudeView.Geo}
        onJsonReceived={this.onJsonReceived}
        onFinishLoading={this.onFinishLoading}
        onScreenCaptured={this.onScreenCaptured}
      />

Permissions

Wikitude needs the camera for display AR.

Android

will ask for permission using the PermissionsAndroid module from React Native. if no permissions was granted, it will render a button to ask again.

IOS

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.

Methods

Events

How to use the module

You can check this example app Github.

Things to considerate:

ChangeLog