cordova-nsr-plugin-v2

1.0.1 • Public • Published


NSR Ionic Cordova Plugin

With Neosurance, Insurers and Communities can offer the right insurance at the right time, creating great customer experiences that drive the adoption of mobile insurance and close the protection gap.


Supported platforms

  • Android 6.0+
  • iOS 10+

Basics

The plugin creates the object Neosurance and is accessible after deviceready has been fired.

Neosurance.NSR_Setup()

The plugin allows hybrid cordova applications to use Neosurance SDK.

Neosurance.NSR_RegisterUser({
  code:"mario@rossi.com",
  email: "mario@rossi.com",
  firstname: "Mario",
  lastname: "Rossi",
  country:"Italia",
  fiscalCode: "RSSMRA85T01F205P",
  address: "Via Canova 12",
  city: "Milano",
  stateProvince: "MI",
  locals:{
    email: "mario@rossi.com",
    firstname: "Mario",
    lastname: "Rossi",
    fiscalCode: "RSSMRA85T01F205P",
    address: "Via Canova 12",
    city: "Milano",
    stateProvince: "MI",
    pushToken : "fake-push"
  }
}, successCallback, failureCallback);

NSREventCruncher

A notification will be detected by the NSR Event Cruncher:

Neosurance.nsr_event_cruncher.EVC.init(successCallback, failureCallback);

Installation

The plugin can be installed via Cordova-CLI and is publicly available on github.

Execute from the projects root folder:

$ ionic cordova plugin add https://github.com/neosurance/cordova-nsr-plugin-v2.git

Or install from local source:

$ ionic cordova plugin add <path> 

Android: After Installation

  1. Inside your AndroidManifest.xml be sure to have the following permissions:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_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.CAMERA" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
  2. Inside your AndroidManifest.xml be sure to have the following activities:

    <activity android:configChanges="orientation|screenSize|keyboardHidden" 
              android:name="eu.neosurance.sdk_ext.NSRActivity" 
              android:screenOrientation="portrait" 
              android:theme="@style/Theme.AppCompat.Light.NoActionBar">
         <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
    </activity>
    
    <activity android:configChanges="orientation|screenSize|keyboardHidden" 
              android:name="eu.neosurance.sdk.NSRActivityWebView" 
              android:screenOrientation="portrait" 
              android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
  3. Inside your AndroidManifest.xml be sure to have the following receivers:

    <receiver android:name="eu.neosurance.sdk.NSRBootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    
    <receiver android:name="eu.neosurance.sdk.NSRFenceCallback" />
    
    <receiver android:name="eu.neosurance.sdk.NSRActivityCallback" />
    
    <receiver android:name="eu.neosurance.sdk.NSRDelayedPush" />
    
    <receiver android:name="eu.neosurance.sdk.NSRBackground" />
  4. Inside your AndroidManifest.xml be sure to have the following service:

    <service android:exported="false" android:name="eu.neosurance.sdk.NSRForeground" />
  5. Inside your AndroidManifest.xml be sure to have the following provider:

     <provider android:authorities="${applicationId}.provider" 
               android:exported="false" 
               android:grantUriPermissions="true" 
               android:name="android.support.v4.content.FileProvider">
         <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
     </provider>
  6. Inside your platforms/android/app/build.gradle replace your statement 'dependencies' and rebuild project:

    /*
     * WARNING: Cordova Lib and platform scripts do management inside of this code here,
     * if you are adding the dependencies manually, do so outside the comments, otherwise
     * the Cordova tools will overwrite them
     */
     
     dependencies {
             implementation fileTree(dir: 'libs', include: '*.jar')
             // SUB-PROJECT DEPENDENCIES START
             implementation(project(path: ":CordovaLib"))
            ...
     }
    

    with

    android {
        compileSdkVersion 29
    
        defaultConfig {
            minSdkVersion 23
            targetSdkVersion 29
            versionCode 1
            versionName "1.0.1"
            multiDexEnabled true
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: '*.jar')
        // SUB-PROJECT DEPENDENCIES START
        implementation(project(path: ":CordovaLib"))
        implementation "com.android.support:support-annotations:27.+"
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support:support-v4:28.0.0'
        implementation 'com.google.android.gms:play-services-location:15.0.1'
        // SUB-PROJECT DEPENDENCIES END
    }
    
  7. Inside your android app java/ be sure to have the following Packages with several files:

     eu.neosurance.
          - cordova 
              (NSRCordovaInterface.java)
          
          - sdk
              (NSR.java)
              (...)
          
          - sdk_ext
              (WFDelegate.java)
              (...)
          
          - utils
              (NSRUtils.java)
              (...)
     ```
    
    

iOS: After Installation

  1. Inside your file.plist be sure to have the following permissions:

    NSRIonic_v4-Info.plist
    
    - Privacy - Location Always and When In Use Usage Description 	[Always and when in use...]
    - Privacy - Location Always Usage Description					[Always...]
    - Privacy - Location When In Use Usage Description				[When in use...]
    - Privacy - Motion Usage Description							[Motion…]
    - Privacy - Camera Usage Description							[For claim...]
  2. Inside your XCode Capabilities be sure to have the following:

    Background Modes ON
    
    - Location updates
    - Bacground fetch
    - Remote notifications
  3. Right Click on eventCruncher.html:

    - Delete -> Remove Reference
    - Add Files to “appname”…
    (check "Copy items if needed","Crete Groups" and "Add to Targets")
    - Click on Add Button
    

Usage

  1. Setup

    Earlier in your Ionic Cordova application startup flow using

    Android

    Neosurance.NSR_Setup(null, successCallback, failureCallback);

    iOS

    var params = {
       "code":"code",
       "base_url":"https://base_url/api/v1.0/",
       "secret_key": "secret_key",
       "dev_mode": true
    };
    
    Neosurance.NSR_Setup(params, successCallback, failureCallback);
  2. Init eventCruncher

    Neosurance.nsr_event_cruncher.EVC.init(successCallback, failureCallback);
  3. User Registration

    Neosurance.NSR_RegisterUser({
     code:"mario@rossi.com",
     email: "mario@rossi.com",
     firstname: "Mario",
     lastname: "Rossi",
     country:"Italia",
     fiscalCode: "RSSMRA85T01F205P",
     address: "Via Canova 12",
     city: "Milano",
     stateProvince: "MI",
     locals:{
       email: "mario@rossi.com",
       firstname: "Mario",
       lastname: "Rossi",
       fiscalCode: "RSSMRA85T01F205P",
       address: "Via Canova 12",
       city: "Milano",
       stateProvince: "MI",
       pushToken : "fake-push"
     }
    }, successCallback, failureCallback);
  4. Set Login Callbacks

    Neosurance.NSR_SetLoginCallback(null, successCallback, failureCallback);
  5. Send Trial Event

    scriptJS.sendEvent({event:'trg1',payload:{fake:1}}, successCallback, failureCallback);
  6. If Login was ok

    Neosurance.NSR_LoginExecuted(null, successCallback, failureCallback);
  7. Show Payments List

    Neosurance.NSR_ShowApp(null, successCallback, failureCallback);
  8. Set Payment Callbacks

    Neosurance.NSR_AppPayment(null, successCallback, failureCallback);
  9. If Payment was ok

    Neosurance.NSR_PaymentExecuted(null, successCallback, failureCallback);
  10. For further information see NSR SDK Docs

    NeosuranceSDK_v3_android

    ...It's mandatory that your securityDelegate implements the default constructor and must be excluded from any obfuscation (ProGuard).
    Then use the setSecurityDelegate method...

Author

info@neosurance.eu

License

NeosuranceSDK is available under the MIT license. See the LICENSE file for more info.

Package Sidebar

Install

npm i cordova-nsr-plugin-v2

Weekly Downloads

3

Version

1.0.1

License

Apache 2.0

Unpacked Size

766 kB

Total Files

74

Last publish

Collaborators

  • aleinfuneosurance