QuickStart

Introduction

The plugin was developed with Flutter version 3.24.5, it contains a sample app that installs a WPA2 certificate. To perform a test it is necessary to enter correct keys. The integration and configuration include a first phase on the Flutter project and a second phase in the individual iOS and Android projects

Flutter installation

Run this command:

With Flutter:

 $ flutter pub add c4w_wifi_sdk_flutter

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  c4w_wifi_sdk_flutter: ^1.0.0

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:c4w_wifi_sdk_flutter/c4w_wifi_sdk_flutter.dart';

Android installation

Integration

To integrate SDK library into your Android project you need to add Cloud4Wi repository inside build.gradle

allprojects {
    repositories {
        google()
        mavenCentral()
        ...
        maven { url = uri("https://artifacts.cloud4wi.com/release") }
        ...
    }
}

dependencies {
    ...

    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.auth0.android:jwtdecode:2.0.0'    
    implementation 'com.cloud4wi:c4w-wifi-sdk:{lib-version}'
}

Add the following in 'application' section of your AndroidManifest.xml file:

<application>
 ...
 <provider
           android:authorities="${applicationId}"
           android:multiprocess="false"
           android:exported="false"
           android:name="com.cloud4wi.sdk.wifi.storage.C4WIMobileSDKContentProvider"/>
</application>

Configuration

In order to connect your application with your Cloud4Wi account, you need to provide SDK with clientKey and clientSecret credentials.

Credentials may be provided to SDK either via configuration property or at runtime. Add two records into your application's string.xml as in examples below:

<resources>
    ...
    <string name="com.cloud4wi.sdk.wifi.api_client_key">{client-key-value}</string>
    <string name="com.cloud4wi.sdk.wifi.api_client_secret">{client-secret-value}</string>
</resources>

Required permissions

AndroidManifest of this library requires following permissions

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Keep the customer update - Init method

To track the last seen date of the customer and to keep always updated the remote push notification token (if applicable) it is necessary to call the method every time the app starts

import com.cloud4wi.sdk.wifi.Cloud4WiSDKWiFi

...
val mobileSDK: Cloud4WiSDKWiFi = Cloud4WiSDKWiFi(applicationContext)
mobileSDK.initC4w()
...

iOS installation

Required Capabilities

In order to use the SDK you have to add the 'Hotspot Configuration' capability to your application

Configuration

In order to connect SDK to your Cloud4Wi account, you have to specify 'clientKey' and 'clientSecret'.

You can set them in your App Info.plist file by adding two following keys:

<key>com_cloud4wi_sdk_wifi_api_client_key</key>
<string>{CLIENT-KEY-VALUE}</string>
<key>com_cloud4wi_sdk_wifi_api_client_secret</key>
<string>{CLIENT-SECRET-VALUE}</string>

Keep the customer update - Init method

To track the last seen date of the customer and to keep always updated the remote push notification token (if applicable) it is necessary to call the method every time the app starts

func initC4w(pushToken: String)

you can put it into didFinishLaunchingWithOptions for example

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    let cloud4WiSDKWiFi = Cloud4WiSDKWiFi.init()
    cloud4WiSDKWiFi.initC4w("remote_push_token")
}

Usage Example

In following code example we will create new customer in the API and then install WPA2-Enterprise Wi-Fi profile . After that when customer will be in range of Wi-Fi network with specified SSID - his device will connect automatically.

This example represents following use-case.

  1. MobileSDK configuration. Setting API client credentials.

  2. Read list of organization policies from API.

  3. Creating new customer in API.

  4. Verifying customer credentials in API.

  5. Creation of WPA2-Enterprise Wi-Fi profile on device for test user to connect to test SSID.

void startRegistration() async {
      try {
        List<String> policiesResponse = await _c4wWifiSdkFlutterPlugin.getListOfPolicies();
        Map<String, String> policiesMap = {
          for (var policy in policiesResponse) policy: 'true'
        };

        setState(()  {
          _statusRegistration ='get Policies completed';
        });
        Customer customer = Customer(
          username: 'userTest',
          password: 'pssTest',
          firstName: 'John',
          lastName: 'Doe',
          phoneNumber: '+393391234567',
          email: 'test.doe@example.com',
          gender: 'Male',
          birthDate: '1990-01-01',
          language: 'en',
          country: 'US',
          zipCode: '12345',
          companyName: 'Example Company',
          civilStatus: 'Mr',
          phoneVerified: true,
          emailVerified: true,
          ppd: false,
          profiling: true,
          custom: {},
          policies: policiesMap,
          document: CustomerDocument(
            memberId: 'memberId',
            number: 'number',
            passportNumber: 'passportNumber',
            personalId: 'personalId',
            type: 'type',
          ),
          lock: false,
          extId: 'external_id_001',
          extProp1: 'extProp1_value',
          extProp2: 'extProp2_value',
        );

        String deduplicateAttribute = 'email';

        try {
          CustomerCreateResponse response =
          await _c4wWifiSdkFlutterPlugin.createCustomer(
            customer,
            deduplicateAttribute,
          );
          setState(()  {
            _statusRegistration ="Customer created successfully: ${response.id}";
          });
          try {
            await _c4wWifiSdkFlutterPlugin.createWPA2EnterpriseProfile(customer.username, customer.password);
          } catch (error) {
            setState(()  {
              _statusRegistration ="Error creating WPA: $error";
            });
          }
          setState(()  {
            _statusRegistration ='WPA Created';
          });
        } catch (error) {
          setState(()  {
            _statusRegistration ="Error creating customer: $error";
          });
        }
      } catch (error) {
        setState(()  {
          _statusRegistration ="Error get policies: $error";
        });
      }
    }
  }

Last updated