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.
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
funcinitC4w(pushToken: String)
- (void) initC4w: (NSString*) pushToken;
you can put it into didFinishLaunchingWithOptions for example