- Tutorials
- Integrating the mimik Client Library into an iOS project
Integrating the mimik Client Library into an iOS project
Objective
The objective of this document is to demonstrate various concepts and techniques that developers need to understand to integrate the mimik Client Library with an iOS application.
Intended Readers
The intended readers of this document are iOS software developers and system integrators using the mimik Client Library when developing an iOS application.
What You'll Be Doing
In this article you'll be covering the following topics that are relevant to integrating the mimik Client Library into an iOS application:
- Configuring a Podfile
- Installing the
MIMIKEdgeClientCore
andMIMIKEdgeClientEngine
pods - Importing mimik Components
- Initializing Components
- Implementing Logging
Technical Prerequisites
This tutorial has the following technical prerequisite: A device running the latest iOS version.
NOTE: Working with the iOS Simulator and the mimik Client Libraries entails some special consideration. For more more information about iOS Simulator support see this tutorial. |
---|
Using the mimik Client Library components in an iOS project
Using the mimik Client Library components in an iOS project is a two-phase process. The phases are:
- Configuring a Podfile
- Executing pod commands
The following sections describe the details of each phase.
Configuring a Podfile
The mimik Client Library components are dependencies that get installed in an iOS project using the CocoaPods dependency manager. Listing 1 below shows an example of a CocoaPods's Podfile
that developers need to use with their iOS projects. The Podfile
defines the source code repository locations containing the relevant dependencies, as shown in Lines 2-3
. It also declares the mimik Client Library pod components at Lines 7-8
. With additional configuration requirements at Lines 11-18
1: platform :ios, '15.0'2: source 'https://github.com/CocoaPods/Specs.git'3: source 'https://github.com/mimikgit/cocoapod-edge-specs.git'4:5: target 'example' do6: use_frameworks!7: pod 'MIMIKEdgeClientCore'8: pod 'MIMIKEdgeClientEngine'9: end10:11: post_install do |installer|12: installer.pods_project.targets.each do |target|13: target.build_configurations.each do |config|14: config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0'15: config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'16: end17: end18: end
Listing 1: A example Podfile for working with mimik Client Library Components
Executing pod commands
Once a Podfile
is configured, developer will run a variety of commands, both from the command line and from within code to get an application using mimik libraries up and running.
The sections that follow describe the details.
Installing mimik components using pod install
Once the dependencies are defined in a Podfile
, developers initiate the installation of MIMIKEdgeClientCore
and MIMIKEdgeClientEngine
pods as well as their dependencies into the iOS project using the following command:
pod install
Running pod install
against the Podfile
a described above displays output similar to the following:
Analyzing dependenciesDownloading dependenciesInstalling AlamofireInstalling AppAuthInstalling JWTDecodeInstalling MIMIKEdgeClientCoreInstalling MIMIKEdgeClientEngineInstalling SwiftyJSONGenerating Pods projectIntegrating client project
At this point, the mimik Client Library components are installed in the iOS project's workspace, ready for use in code.
Importing mimik Components
Before developers can initialize the mimik Client Library components, they need to import the MIMIKEdgeClientCore
and MIMIKEdgeClientEngine
component references into their class. The code example below shows you how to use the import
command inline in code to import mimik component libraries.
import MIMIKEdgeClientCoreimport MIMIKEdgeClientEngine
Initializing Components
In order to get the mimik Client Library components up and running in an iOS project, developers need to initialize them. Listing 2 below shows an example of how to create instances of the two mimik Client Library components within a class.
1: import MIMIKEdgeClientCore2: import MIMIKEdgeClientEngine3:4: let edgeClient: MIMIKEdgeClient = {5: return MIMIKEdgeClient()6: }()7:8: let edgeEngine: MIMIKEdgeClientEdgeEngine = {9: guard let mimikEdgeEngine = MIMIKEdgeClientEdgeEngine() else {10: fatalError("Error")11: }12: return mimikEdgeEngine13: }()
Listing 2: The code for initializing the mimik Client Library Components in an iOS application
Notice the code MIMIKEdgeClient()
at Line 5.
This is where the instance of MIMIKEdgeClientCore
gets created.
Additionally, notice the guard let mimikEdgeEngine = MIMIKEdgeClientEdgeEngine()
code at Line 9
. This is where the instance of MIMIKEdgeClientEngine
gets created. Since the MIMIKEdgeClientEngine
initializer is failable, this line does a guard check, making sure no errors have occurred.
With that, the mimik Client Library Core and Engine components have been initialized and are ready for use.
Implementing Logging
Console logging is an important tool for developers when debugging software issues. The mimik Client Library provides a customizable console logging system that developers can configure to suit their needs. The code example below in Listing 3 shows you how to do this.
1: func setupLogging() {2: // Setting the debug level for the Core component3: MIMIKEdgeClient.setLoggingLevel(level: .debug, subsystem: .mimikEdgeClientCore)4: // Setting the error level for the Engine component5: MIMIKEdgeClient.setLoggingLevel(level: .error, subsystem: .mimikEdgeClientEngine)6: // Logging options are also available for a custom component7: MIMIKEdgeClient.setLoggingLevel(level: .debug, subsystem: .custom("MyApp"))8: }
Listing 3: Setting up logging using the mimik Client Library
NOTE: For more information about the available logging methods, see the MIMIKLog class. |
---|