Developer Hub
SupportDashboardGuides
Developer hub
Developer hub
  • Home
  • WiFi SDK
    • Overview
    • Integrating the SDK
      • iOS
        • QuickStart
        • SDK methods
          • initC4w
          • createCustomer
          • setupCustomer
          • createWPA2EnterpriseProfile
          • createPasspointProfile
          • getCreatedWPA2EnterpriseProfiles
          • getCreatedPasspointProfiles
          • getCustomerId
          • getCustomerInfo
          • updateCustomer
          • updateCustomerInfo
          • checkIfCustomerExists
          • getListOfPolicies
          • deletePasspointProfile
          • deleteWPA2EnterpriseProfile
          • setAPIAuthParams
          • setInterlinkedC4WIMobileSDKApplications
          • getInterlinkedC4WIMobileSDKApplications
          • logout
        • Objects
          • Customer
          • CustomerDocument
          • CustomerCreateResponse
          • CustomerInfo
          • CustomerQuery
          • WPA2EnterpriseProfile
          • PasspointProfile
        • Additional features
        • Changelog
      • Android
        • QuickStart
        • SDK methods
          • initC4w
          • createCustomer
          • setupCustomer
          • createWPA2EnterpriseProfile
          • deleteWPA2EnterpriseProfile
          • createPasspointProfile
          • deletePasspointProfile
          • isPasspointSupported
          • getCustomerId
          • getCustomerInfo
          • checkIfCustomerExists
          • updateCustomer
          • updateCustomerInfo
          • getListOfPolicies
          • setAPIAuthParams
          • getCreatedWPA2EnterpriseProfiles
          • getCreatedPasspointProfile
          • setInterlinkedC4WIMobileSDKApplications
          • getInterlinkedC4WIMobileSDKApplications
          • logout
        • Objects
          • Customer
          • CustomerDocument
          • CustomerCreateResponse
          • CustomerInfo
          • CustomerQuery
          • WPA2EnterpriseProfile
          • PasspointConfiguration
        • Additional features
        • Troubleshooting
        • Changelog
      • Flutter
        • QuickStart
        • Changelog
    • User experience
    • FAQ
  • Location SDK
    • Overview
    • Integrating the SDK
      • Android
        • Quickstart
        • Project initialization
        • SDK Methods
          • Enable/Disable
          • Handling blocking issues
          • Get Device Id
          • Reset device Id
          • Locations of Interest
            • Home location
            • Work location
        • Changelog
      • iOS
        • QuickStart
        • Installation
        • Project initialization
        • SDK methods
          • Initialization
          • Enable/Disable
          • Get Device Id
          • Reset device Id
          • Locations of interest
            • Home location
            • Work location
        • Reference versions
        • Changelog iOS
      • Flutter
        • QuickStart
        • Changelog
  • Demo toolkit
    • Demo app
    • Testlab WiFi setup
  • API Reference
    • Getting started
      • Authentication
      • Contacts
      • Locations
      • Geofences
      • Devices
      • Segments
      • WiFi logs
      • Events
    • Webhooks
    • Use cases
    • Legacy APIs (v2)
  • MyApps
    • My App Intro
    • Creating Apps
      • Access Journey Apps
      • Apps for the Dasbhoard
    • MyApps APIs and SDK
      • Access Journey SDK
      • REST APIs in MyApp
      • Context APIs
    • Sample projects
      • MyApps -Js SDK boilerplate
      • Video Advertising
      • Typeform integration
      • Facebook Pixel in Acces Journey
  • Tutorials
    • Sample onboarding flow for new app users
    • Integrating WiFi SDK in Flutter apps
Powered by GitBook
On this page
  • Sample app boilerplate
  • Installation
  • Configuration
  • Required Capabilities
  • Usage example
  • Keep the customer update

Was this helpful?

Export as PDF
  1. WiFi SDK
  2. Integrating the SDK
  3. iOS

QuickStart

PreviousiOSNextSDK methods

Last updated 1 year ago

Was this helpful?

Sample app boilerplate

The following app demonstrates an example of using the WiFi SDK (and the Location SDK).

The app is ready to run but you have to set your own credentials by putting them into plist file. To test the WiFi section, based on Passpoint, you have to use a physical iOS device and have an access point configured in a Cloud4Wi account.

Installation

CocoaPods

Add pod 'c4w-wifi-sdk' to your Podfile and run pod install.

Swift Package Manager

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>

Required Capabilities

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

Usage example

This example represents the following use-case:

  1. Read the list of organization policies (the term "policies" is used to refer to consents and agreements that are configured on the Cloud4Wi account)

  2. Creating new customer

  3. Verifying customer credentials in API by retrieving customer info (optional)

  4. Create WPA2-Enterprise Wi-Fi profile on iOS device

let cloud4WiSDKWiFi = Cloud4WiSDKWiFi.init()
var error: NSError? = nil

// Policies
cloud4WiSDKWiFi.getListOfPolicies { (policies) in
	if let policies = policies {
		var approvedPolicies: Dictionary = [String: String]()
		for policy in policies {
			approvedPolicies[policy] = "true"
		}
		let customer = Customer()
		customer?.firstName = "John"
		customer?.lastName = "Red"
		customer?.email = "john@cloud4wi.com"
		customer?.policies = approvedPolicies
		
		cloud4WiSDKWiFi.createCustomer(customer, deduplicate: "email") { (customerResponse) in
			if let customerResponse = customerResponse {
				print("INFO: Customer successfully created")
				cloud4WiSDKWiFi.getCustomerInfo(customerResponse.username, password: customerResponse.password) { (info) in
					print("INFO: Customer with provided credentials exists")
					if let username = customerResponse.username, let password = customerResponse.password {
						self.createCertificateWithUser(username, andPassword: password, andMobileSDK: cloud4WiSDKWiFi, success: success)
					}
				} onError: { (error) in
					if let error = error {
						DispatchQueue.main.async {
							print("ERROR. Cannot check credentials:")
							success(false)
						}
						return
					}
				}
			} else {
				DispatchQueue.main.async {
					print("No customerResponse found")
					success(false)
				}
				return
			}
		} onError: { (error) in
			if let error = error as NSError? {
				DispatchQueue.main.async {
					print("ERROR. Cannot create customer")
					success(false)
				}
				return
			}
		}
	} else {
		DispatchQueue.main.async {
			print("No policies found")
			success(false)
		}
		return
	}
} onError: { (error) in
	DispatchQueue.main.async {
		if let error = error {
			print("ERROR. get list of policies")
			success(false)
		}
		return
	}
}
NSError *e = nil;
Cloud4WiSDKWiFi *cloud4WiSDKWiFi = [[Cloud4WiSDKWiFi alloc] init];
   /*
    * OPTIONAL - Retrieve the list of policies configured in Cloud4Wi, including custom ones
    */
   [cloud4WiSDKWiFi getListOfPolicies: ^(NSArray<NSString *> *policies) {
       NSLog(@"INFO: Policies successfully obtained from API");
       
       /*
        * Init Customer object with all optional attributes
        */
       Customer* customer = [[Customer alloc] init];
       [customer setFirstName:@"John"];
       [customer setLastName:@"Red"];
       [customer setExtId:@"12345677810"];    
       [customer setEmail:"john@cloud4wi.com"];

       /*
        * In order to register new customer the policies in position 0 (termsOfUse) and 1 (privacy) 
        * returned by getListOfPolicies must be set to true
        */
       NSMutableDictionary *approvedPolicies = [[NSMutableDictionary alloc] init];
       for (NSString* policy in policies) {
           [approvedPolicies setObject:@"true" forKey:policy];
       }
       [customer setPolicies:approvedPolicies];
        
        
       /*
        * Create Customer in Cloud4Wi account. If not provided, WiFi username and password 
        * are assigned automatically and returned in the method response
        */
       [cloud4WiSDKWiFi createCustomer:customer deduplicate:nil onSuccess:^(CustomerCreateResponse *customerCreateResp) {
           NSLog(@"INFO: Customer successfully created");
            
            /*
             * OPTIONAL - Assure new customer has been successfully created by checking newly created customer's credentials
             */
           [cloud4WiSDKWiFi getCustomerInfo:[customerCreateResp username] password:[customerCreateResp password] onSuccess:^(CustomerInfo *resp) {
               NSLog(@"INFO: Customer with provided credentials exitsts");
                
                /*
                 * Create WPA2-Enterprise Wi-Fi Profile for recently created new customer
                 * using the username/password returned by the createCustomer method
                 */
               [cloud4WiSDKWiFi createWPA2EnterpriseProfile:[customerCreateResp username] password:[customerCreateResp password] onSuccess:^{
                   NSLog(@"INFO: Wi-Fi profile successfully created");
               } onError:^(NSError *error) {
                   NSLog(@"ERROR. Cannot create Wi-Fi profile: %@", [error localizedDescription]);
               }];                            
           } onError:^(NSError *error) {
               NSLog(@"ERROR. Cannot check credentials: %@", [error localizedDescription]);
           }];
       } onError:^(NSError *error) {
           NSLog(@"ERROR. Cannot create customer: %@", [error localizedDescription]);
       }];
   } onError: ^(NSError *error) {
       NSLog(@"ERROR. Cannot get list of policies: %@", [error localizedDescription]);
}];

Keep the customer update

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)
- (void) initC4w: (NSString*) pushToken; 

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")
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    Cloud4WiSDKWiFi *cloud4WiSDKWiFi = [[Cloud4WiSDKWiFi alloc] init];
    [cloud4WiSDKWiFi initC4w:@"remote_push_token"];
}

https://github.com/Cloud4Wi-Create/iOS-WifiSDK-SwiftPackage
21KB
ios-integration-app-master.zip
archive
Example integration app