Using the iOS SDK

Software requirements

The iOS SDK has the following sofware requirements:

  • Xcode 10.3+

  • iOS 11.0+

  • Swift 5.0+

Installing dependency managers

The following section describes how you get the SDK up and running. Use the following for dependency management for the iOS SDK:

  • Carthage is a dependency manager written in Swift. It builds your dependencies and provides you with binary frameworks while you retain control over your project structure and setup.

  • CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. The file with the specification that describes the dependencies of the targets of one or more Xcode projects is called Podfile.

Carthage

To install Carthage:

github "gesundheitscloud/hc-sdk-ios"

CocoaPods

To add a private CocoaPods specs repository to the Podfile, enter the following:

source 'git@github.com:gesundheitscloud/cocoapods-specs.git'

To add the framework to the Podfile, enter the following:

pod 'HCSDK'

For more info, see the README file.

Dependencies of the SDK

The iOS SDK has the following dependencies:

Setting up the SDK

To set up the iOS SDK, perform the following steps:

  1. Configure the client information

  2. Handle the OAuth 2.0 redirect URL

  3. Define the environment

  4. Display the login screen

The following section describes these steps in more detail.

  1. Prepare the SDK for use by configuring the client information. This must be the first SDK call. Otherwise, the client crashes.

    import UIKit
    import HCSDK
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
      var window: UIWindow?
    
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
    
        let clientId = "client-id#ios"
        let secret = "secret"
        let redirectURLString = "app://oauth"
        HCSDKClient.configureWith(clientId: clientId,
                                  clientSecret: secret,
                                  redirectURLString: redirectURLString)
    
        return true
      }
    }
  2. Handle the OAuth 2.0 redirect URL in the AppDelegate class.

    import UIKit
    import HCSDK
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
      var window: UIWindow?
    
      func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    
        HCSDKClient.default.handle(url: url)
    
        return true
      }
    }
  3. Set the proper environment if necessary, production is the default environment.

    import UIKit
    import HCSDK
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
      var window: UIWindow?
    
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
    
        HCSDKClient.environment = .development
    
        return true
      }
    }
  4. Display the login screen. You can then use it throughout the app with the default client by providing a view controller to present.

    let viewController = UIApplication.shared.keyWindow?.rootViewController
    HCSDKClient.default.presentLogin(on: viewController, animated: true) { result in
        switch result {
        case .success:
            // Handle success
        case .failure(let error):
            // Handle error
        }
    }
  5. Optional: To use the SDK inside extensions, provide the keychainGroupId identifier when you configure the SDK and enable the KeychainSharing capability in the Xcode project. The SDK also requires the AppGroups capability with the same setup.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
    
        let clientId = "client-id#ios"
        let secret = "secret"
        let redirectURLString = "app://oauth"
        let teamId = "TEAMDID"
        let groupId = "Group1"
        let keychainGroupId = "\(teamId).\(groupId)"
        let appGroupId= "group.unique.id"
    
        HCSDKClient.configureWith(clientId: clientId,
                                  clientSecret: secret,
                                  redirectURLString: redirectURLString,
                                  keychainGroupId: keychainGroupId,
                                  appGroupId: appGroupId)
    
        return true
      }

This website uses cookies - see our privacy policy for more information about cookies and your rights as a user. Click on "accept" to allow the cookie use.
More about this