Git Product home page Git Product logo

ios-sdk's Introduction

Clever iOS SDK

CleverSDK is a simple iOS library that makes it easy for iOS developers to integrate Clever Instant Login into their application. You can read more about integrating Clever Instant Login in your app here.

Usage

Configure your Clever application to support the iOS redirect URL.

You can create an iOS redirect URL by going to https://apps.clever.com/partner/applications and clicking View / Edit on your application.

Click on the "Enable iOS Platform" button (contact Clever Support if option is not available).

You will then get access to a client ID and redirect URI you can use for your iOS app.

You can also set a "fallback URL" where users will be redirected if they don't have your app installed.

Configure your iOS app

Once you have the custom redirect URL, add it to your application as a custom URL scheme. If you are not sure how to do so, you can read this tutorial for help.

Finally, add com.clever to your LSApplicationQueriesSchemes in your Info.plist, so you can redirect directly to the Clever app. More information on LSApplicationQueriesSchemes can be found here.

Sign in with Clever

Once the app configuration has been updated, add the following code to the application:didFinishLaunchingWithOptions: method in AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Start the CleverSDK with your client
    // Do not forget to replace CLIENT_ID with your client_id
    [CLVOAuthManager startWithClientId:@"CLIENT_ID" successHandler:^(NSString * _Nonnull accessToken) {
        NSLog(@"success");
    } failureHandler:^(NSString * _Nonnull errorMessage) {
        NSLog(@"failure");
    }];
    
    // To support iOS 9/10, you must set the UIDelegate to the UIViewController 
    // that will be displayed when the user is logging in.
    MyLoginViewController *vc = [[MyLoginViewController alloc] initWithNibName:nil bundle:nil];
    self.window.rootViewController = vc;
    [CLVOAuthManager setUIDelegate:vc]

    // Alternatively, you can initialize CLVOAuthManager without success/failure blocks and instead use the delegate pattern.
    // See "Delegate Pattern" below for handling completion when using the delegate pattern
    // [CLVOAuthManager startWithClientId:@"CLIENT_ID"];
    // [CLVOAuthManager setDelegate:self];
}]

Besides the above change, you also need to add some code to handle the iOS redirect URI. This is done by implementing the application:openURL:sourceApplication:annotation: method of the AppDelegate:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    // Clever's URL handler
    return [CLVOAuthManager handleURL:url sourceApplication:sourceApplication annotation:annotation];
}

Log in with Clever Button

You can also set up a Log in with Clever Button. In the UIViewController set as the UIDelegate, add the following code to the viewDidLoad method:

// Create a "Log in with Clever" button
loginButton = [CLVLoginButton createLoginButton];
[self.view addSubview:loginButton];

The button is instantiated with a particular width and height. You can update the width of the button by calling setWidth: method on the button:

[self.loginButton setWidth:300.0];

Delegate Pattern

If you are using the delegate pattern instead of completion blocks, add the following method to your AppDelegate.m:

// If non-null blocks are provided, signInToClever:withError: will not be called
- (void)signInToClever:(NSString *)accessToken withError:(NSString *)error {
    if (error) {
        // error
    }
    // success
}

To run the example project, clone the repo, and run pod install from the Example/SimpleLogin directory first.

Installation

CleverSDK is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "CleverSDK"

License

Apache 2.0

ios-sdk's People

Contributors

alsmola avatar peternga avatar streeter avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.