Skip to content

Get Started

Preparations

Add Npm Registry

1
npm login --registry=https://telenav.jfrog.io/artifactory/api/npm/telenav-npm-releases/ --scope=@telenav

Add Npm Package

Run command to add package:

1
yarn add @telenav/react-native-data-collector-bridge@<version>
or
1
npm install @telenav/react-native-data-collector-bridge@<version>

Android Installation

Currently, android version of Data Collector only supports three platforms with architecture arm64-v8a, armv7a and x86_64 with SDK Android 6.0 (API level 23) to Android 11 (API level 30).

Add Build Script

  1. Add lines to android/build.gradle
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    ext {
        ...
        minSdkVersion = 23
     }
     allprojects {
        repositories {
          ...
          maven {
             url "https://telenav.jfrog.io/artifactory/telenav-maven-releases/"
             credentials {
               username '#REPO_USER_NAME#'
               password '#REPO_PASSWD#'
             }
           }
        }
    }
    

Add Java Code into Activity to Support Background Mode

Check Background Permission

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
    private static void checkBackgroundPermission(Activity activity) {
        String[] permissions;
        int mPermissionRequestCode = 1234;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            permissions =
                    new String[]{
                            Manifest.permission.ACCESS_COARSE_LOCATION,
                            Manifest.permission.ACCESS_FINE_LOCATION,
                            Manifest.permission.ACCESS_BACKGROUND_LOCATION,
                            Manifest.permission.READ_PHONE_STATE
                    };
        } else {
            permissions =
                    new String[]{
                            Manifest.permission.ACCESS_COARSE_LOCATION,
                            Manifest.permission.ACCESS_FINE_LOCATION,
                            Manifest.permission.READ_PHONE_STATE
                    };
        }
        ActivityCompat.requestPermissions(activity, permissions, mPermissionRequestCode);
    }

Check Ignore Battery Optimization

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
    private static void checkIgnoreBatteryOptimization(Context context) {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                Intent intent = new Intent();
                PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                boolean hasIgnore = powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
                if (!hasIgnore) {
                    intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
                    intent.setData(Uri.parse("package:" + context.getPackageName()));
                }
                context.startActivity(intent);
            }
        } catch (Exception e) {
            Log.e(TAG, "checkIgnoreBatteryOptimization meet exception: " + e.getMessage());
        }
    }

Add Permissions to Support Background Mode

Add permissions to AndroidManifest.xml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
...
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
...

Note

If battery optimization is enabled, event won't be uploaded and background mode won't be supported!

iOS Installation

Need CocoaPods, cocoapods-art plugin and correctly configured Podfile. If you don't have cocoapods-art installed, you need to run gem install cocoapods-art to install it.

Add CocoaPods Requirements

1
2
3
4
5
6
7
source 'https://cdn.cocoapods.org/'
...
platform :ios, '10.0'

plugin 'cocoapods-art', :sources => [
  'telenav-cocoapods'
]

Install / Update CocoaPods Repository

Run command

1
pod repo-art add telenav-cocoapods "https://telenav.jfrog.io/artifactory/api/pods/telenav-cocoapods"
or
1
pod repo-art update telenav-cocoapods
to update local cocoapods repository, as well as delete Podfile.lock file.

Install Dependencies

Run command pod install to install dependencies.

Add Usage Description to Support Background Mode

You must update Info.plist with a usage description for location and motion.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
...
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Do you allow this app to know your current location?</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Will you allow this app to always know your location?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Do you allow this app to know your current location?</string>
<key>NSMotionUsageDescription</key>
<string>Do you allow this app to track you motion data?</string>
...
<key>UIBackgroundModes</key>
<array>
    <string>fetch</string>
    <string>location</string>
    <string>processing</string>
</array>
<key>UIFileSharingEnabled</key>
<true/>
...

Troubleshooting

1. Error: undefined symbol: swift._arraybuffer._copycontents

** This issue can be fixed from the project side**:

  1. remove "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" from library search paths.
  2. add empty Swift file with bridging header (XCode will ask about this header when you create first Swift file).
  3. if build still fails, set "Always embed Swift standard libraries" to "Yes" (but it should be set automatically).