The SCiO API includes complete Login functionality, including a login screen. You must use the Login functionality provided, and cannot create your own Login screen.

After the end user logs in for the first time, an access token is saved on the user’s mobile device. As the access token does not have an expiry date, the end user does not need to log in again.

The following code example demonstrates how to activate the SCiO login activity, get the access token, and save it on the user’s mobile device:

#import <ScioSDK/ScioSDK.h>
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 
    NSLog(@"ScioSDKVersionNumber: %.2f",ScioSDKVersionNumber);
    // Override point for customization after application launch.
    [[CPScioCloud sharedInstance] setCliend_id:@"4b5ac28b-28f9-4695-b784-b7665dfe3763"];
    [[CPScioCloud sharedInstance] setRedirect_uri:@"https://www.consumerphysics.com"];
 
    return YES;
}

You can remove the access token using [[CPScioCloud sharedInstance] logout];

Once the access token is deleted the user needs to log in to the app again.

There are two options to login:

1. Create it programatically and present it using your current view controller.

CPScioLoginViewController will preset login form.

It will dismiss itself upon completion of login action (successful or failure).

// Activate the SCiO Login screen.

(void) login{

CPScioLoginViewController *vc = [[CPScioLoginViewController alloc] init];

[self presentViewController:vc animated:YES completion:nil];

}

2. The “showLoginWithCompletion” method.
In this case, it won’t dismiss itself, and the caller can use the completion to dismiss the view
controller.

Input parameters:
completion- success is used for login success/failure. error contains the error in case of failure
(reason is available in error userInfo).
inNavigationController- show login screen in navigation controller. If &quot;Yes&quot;, login view controller
contains a &quot;cancel&quot; button.
presentingViewController- current view controller to display the login view controller.
- (void)loginAPI {
    NSLog(@"loginAPI");
    CPScioLoginViewController *vc = [CPScioLoginViewController loginViewController];
    __weak typeof(&*vc)weakVC = vc;
    __weak typeof(&*self)weakSelf = self;
    
    [vc showLoginWithCompletion:^(BOOL success, NSError *error) {
        if (success) {
            [weakSelf getUserInfo];
            [weakVC dismissViewControllerAnimated:YES completion:nil];
        } else {
            [weakVC dismissViewControllerAnimated:YES completion:nil];
            [weakSelf alertWithTitle:@"Failed to login" message:error.userInfo[@"Error"]];
        }
    } inNavigationController:YES presentingViewController:self];
}

Note: 3rd party application users without a SCiO account can create an account by clicking “sign up” on the Login page.