Skip to content

kingschat/KingsLogin-ios

Repository files navigation

KingsChat For Developers

Version License Platform

This library allows your app to login using Kingschat.
Written in Swift 4.2
Supported iOS version 11.0 and higher

Installation Guide

Create your app in Kingschat Dashboard

  1. Navigate to your project folder in terminal
  2. Make sure you have the CocoaPods installed
  3. Add pod 'KCLoginSDK' to your Podfile
  4. Run the following command in your project root directory from a terminal window $ pod install

App implementation

  1. Configure info.plist file
  • Right click info.plist, and choose Open As Source Code
  • Copy and paste the following XML snippet into the body of your file ( <dict>...</dict>).
<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>kc-[YOUR_CLIENT_ID]</string>
		</array>
	</dict>
</array>
<key>KingschatClientId</key>
<string>[YOUR_CLIENT_ID]</string>
<key>LSApplicationQueriesSchemes</key>
<array>
	<string>kingschat</string>
</array>
  1. Connect your AppDelegate
  • Set delegate
   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
       // Initialize KingsChat login
       LoginManager.delegate = self
       return true
   }
  • Handle KingsChat URL
   func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
       let sourceAppName = options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String
       let handled = LoginManager.handle(url, sourceAppName: sourceAppName)
       return handled
   }
  • Implement KCLoginManagerDelegate
extension AppDelegate: KCLoginManagerDelegate {
   func login(succeededWith response: KCLoginResponse) {
       print(response.authCode.value)
   }

   func login(failedWithError error: KCLoginError) {
       print(error.message)
   }
}
  1. Add Kingschat login to your code
import UIKit
import KCLoginSDK

class ViewController: UIViewController {
	private lazy var button: KCLoginButton = {
		let button = KCLoginButton()
		return button
	}()
	
	override func viewDidLoad() {
		super.viewDidLoad()
		view.addSubview(button)
	}
}

Example

For more information about implementation check our example app

About

Integrate your iOS apps in Swift with KingsChat Platform.

Resources

License

Stars

Watchers

Forks

Packages

No packages published