Tutorials
EdgeMobileClient iOS wrapper
MIMIKEdgeMobileClient
This guide explains what you need to do in order to integrate mimik edgeEngine into your iOS projects with a cocoapod.
CocoaPods Installation
The easiest way to integrate edgeEngine to an iOS project is with the MIMIKEdgeMobileClient cocoapod by making the following changes to your Podfile:
platform :ios, '13.0'
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/mimikgit/cocoapod-edge-specs.git'
target 'your_target' do
pod 'MIMIKEdgeMobileClient'
end
Learn more about CocoaPods
Client Library Features
- edgeEngine startup, shutdown and automatic background state management.
- Custom edgeEngine configuration and startup parameters.
- Automatic or manual edgeEngine runtime port management.
- edgeEngine runtime and identification information APIs.
- microservice deployment process APIs.
- Fully parsed objects representing deployed microservices, their containers, images and all of their properties.
- mimik authentication services APIs. (platform, developer, tenant phone, tenant email, tenant federation)
- mimik tenant profile service APIs.
- mimik tenant device notification service APIs.
- mimik tenant assessment service APIs.
- mimik tenant tracker service APIs.
- mimik tenant content caching service APIs.
- Automatic access token management (edgeEngine, platform and tenant services) via mimik client library adapter code (ask us about the details).
- Automatic mimik tenant services response validation, object decoding and parsing using Swagger hub models.
- Fully parsed objects representing mimik tenant service entities and all of their properties.
- Objects store for storing access tokens, mimik tenant service objects and strings.
- Multiple backends support.
Client library initialization
Description
Import MIMIKEdgeMobileClient module and initialize its instance.
Example Code
import MIMIKEdgeMobileClient
let mimikClient = MIMIKEdgeMobileClient.init()
edgeEngine startup
Description
edgeEngine startup API with a completion block. Also protocol delegate registration.
Example Code
self.edgeMobileClient.delegate = self
self.edgeMobileClient.startEdge { (result) in
DispatchQueue.main.async {
guard result.error == nil, let _ = result.status else {
return
}
print("mimik edge started.")
}
}
Platform shutdown
Description
Platform shutdown with a completion block.
Example Code
self.edgeMobileClient.stopEdge { (result) in
DispatchQueue.main.async {
guard result.error == nil, let _ = result.status else {
return
}
print( "mimik edge stopped.")
}
}
Platform authorization
Description
Platform authorization with a completion block; provides platform access token.
Example Code
Wrapper API call
guard let checkedAuthConfig = self.authConfig() else {
return
}
// let's call the mimik identity provider, first iOS will show a system popup informing the user that an authentication is about to take place at mimik360.com
// mimik360.com is the home of mimik identity providers services
self.edgeMobileClient.authorize(authConfig: checkedAuthConfig, viewController: self) { (result) in
DispatchQueue.main.async {
guard result.error == nil else {
return
}
let platformAccessToken = "\(result.status?.accessToken ?? "none")"
print( "Authorized. Platform access token received.")
print("platform access token: \(platformAccessToken)")
}
}
Wrapper API call configuration
// mimik identity provider authentication configuration
func authConfig() -> MIMIKAuthConfig? {
guard let checkedRedirectURL = URL.init(string: "YOUR_REDIRECT_URL_FROM_DEVELOPER_CONSOLE") else {
return nil
}
let clientId = self.clientId()
return MIMIKAuthConfig.init(clientId: clientId, redirectUrl: checkedRedirectURL, additionalScopes: nil, authorizationRootUrl: nil)
}
// get or set this value at mimik developer portal dashboard
// https://developer.mimik.com/console/project/dashboard/
func redirectUrl() -> URL? {
return URL.init(string: "YOUR_REDIRECT_URL_FROM_DEVELOPER_CONSOLE")
}
// get this value at mimik developer portal dashboard
// https://developer.mimik.com/console/project/dashboard/
func clientId() -> String {
return "YOUR_CLIENT_ID_FROM_DEVELOPER_CONSOLE"
}
Platform Unauthorization
Description
Platform unauthorization with a completion block; resets platform content.
Example Code
Wrapper API call
guard let checkedAuthConfig = self.authConfig() else {
return
}
self.edgeMobileClient.unauthorize(authConfig: checkedAuthConfig, viewController: self) { (result) in
DispatchQueue.main.async {
guard result.error == nil else {
return
}
print("UnAuthorized.)
}
}
Wrapper API call configuration
// mimik identity provider authentication configuration
func authConfig() -> MIMIKAuthConfig? {
guard let checkedRedirectURL = URL.init(string: "YOUR_REDIRECT_URL_FROM_DEVELOPER_CONSOLE") else {
return nil
}
let clientId = self.clientId()
return MIMIKAuthConfig.init(clientId: clientId, redirectUrl: checkedRedirectURL, additionalScopes: nil, authorizationRootUrl: nil)
}
// get or set this value at mimik developer portal dashboard
// https://developer.mimik.com/console/project/dashboard/
func redirectUrl() -> URL? {
return URL.init(string: "YOUR_REDIRECT_URL_FROM_DEVELOPER_CONSOLE")
}
// get this value at mimik developer portal dashboard
// https://developer.mimik.com/console/project/dashboard/
func clientId() -> String {
return "YOUR_CLIENT_ID_FROM_DEVELOPER_CONSOLE"
}
Deploying Microservices
Description
Microservice deployment with a completion block; platform access token is required.
Example Code
Wrapper API call
guard let microServiceDeploymentConfig = self.microserviceDeploymentConfig() else {
return
}
self.edgeMobileClient.deployMicroservice(config: microServiceDeploymentConfig) { (result) in
DispatchQueue.main.async {
guard result.error == nil, let _ = result.status else {
print("mimik edge not running?")
return
}
print("Deployed.")
}
}
Wrapper API call configuration
func microserviceDeploymentConfig() -> MIMIKMicroserviceDeploymentConfig? {
guard let checkedMicroserviceBundlePath = self.microserviceImageTarPath(), FileManager.default.fileExists(atPath: checkedMicroserviceBundlePath) else {
return nil
}
guard let checkedPlatformAccessToken = self.platformAccessToken as String? else {
return nil
}
return MIMIKMicroserviceDeploymentConfig.init(edgeAccessToken: checkedPlatformAccessToken, imageName: self.microserviceImageName(), containerName: self.microserviceContainerName(), baseApiPath: self.microserviceBaseApiPath(), imageTarPath: checkedMicroserviceBundlePath, envVariables: self.microserviceEnvVariables())
}
func microserviceImageName() -> String {
return "example-v1"
}
func microserviceContainerName() -> String {
return "example-v1"
}
func microserviceBaseApiPath() -> String {
return "/" + self.clientId() + "/example/v1"
}
// This is where the .tar micro service is stored in the application's bundle
func microserviceImageTarPath() -> String? {
let microServiceTarFilename = "example-v1"
let microServiceBundlePath = Bundle.main.path(forResource: microServiceTarFilename, ofType: ".tar")
return microServiceBundlePath
}
func microserviceEnvVariables() -> [String:String] {
var envVariables: [String: String] = [:]
guard let checkedPlatformServiceLink = self.platformServiceLink() else {
return envVariables
}
envVariables = ["uMDS" : checkedPlatformServiceLink + "/mds/v1", "MCM.WEBSOCKET_SUPPORT" : "true"]
return envVariables
}
func platformServiceLink() -> String? {
return self.edgeMobileClient.platformServiceLink()
}
// get this value at mimik developer portal dashboard
// https://developer.mimik.com/console/project/dashboard/
func clientId() -> String {
return "YOUR_CLIENT_ID_FROM_DEVELOPER_CONSOLE"
}
Undeploying microservices
Description
Microservice undeployment with a completion block; platform access token is required.
Example Code
Wrapper API call
guard let config = microserviceUndeploymentConfig() else {
return
}
self.edgeMobileClient.undeployMicroservice(config: config) { (result) in
DispatchQueue.main.async {
guard result.error == nil, let _ = result.status else {
print( "mimik edge not running?")
return
}
print("Undeployed.")
}
}
Wrapper API call configuration
func microserviceUndeploymentConfig() -> MIMIKMicroserviceUndeploymentConfig? {
guard let checkedPlatformAccessToken = self.platformAccessToken else {
return nil
}
return MIMIKMicroserviceUndeploymentConfig.init(edgeAccessToken: checkedPlatformAccessToken, imageName: self.microserviceUndeploymentImageName(), containerName: self.microserviceUndeploymentContainerName())
}
func microserviceImageName() -> String {
return "example-v1"
}
func microserviceContainerName() -> String {
return "example-v1"
}
func microserviceBaseApiPath() -> String {
return "/" + self.clientId() + "/example/v1"
}
func microserviceUndeploymentImageName() -> String {
return self.clientId() + "-" + self.microserviceImageName()
}
func microserviceUndeploymentContainerName() -> String {
return self.clientId() + "-" + self.microserviceContainerName()
}
// This is where the .tar micro service is stored in the application's bundle
func microserviceImageTarPath() -> String? {
let microServiceTarFilename = "example-v1"
let microServiceBundlePath = Bundle.main.path(forResource: microServiceTarFilename, ofType: ".tar")
return microServiceBundlePath
}
func microserviceEnvVariables() -> [String:String] {
var envVariables: [String: String] = [:]
guard let checkedPlatformServiceLink = self.platformServiceLink() else {
return envVariables
}
envVariables = ["uMDS" : checkedPlatformServiceLink + "/mds/v1", "MCM.WEBSOCKET_SUPPORT" : "true"]
return envVariables
}
func platformServiceLink() -> String? {
return self.edgeMobileClient.platformServiceLink()
}
// get this value at mimik developer portal dashboard
// https://developer.mimik.com/console/project/dashboard/
func clientId() -> String {
return "YOUR_CLIENT_ID_FROM_DEVELOPER_CONSOLE"
}
Listing Deployed Microservices
Description
Lists currently deployed images and containers in a completion block.
Example Code
guard let checkedPlatformAcessToken = self.platformAccessToken else {
return
}
self.edgeMobileClient.getDeployedContainers(edgeAccessToken: checkedPlatformAcessToken) { (result) in
guard result.error == nil, let checkedContent = result.content, JSON.init(checkedContent) != JSON.null else {
print("mimik edge not running?")
return
}
let json = JSON.init(checkedContent)
let data = json["data"]
print(data.debugDescription)
}
Platform Instance Information
Description
Platform instance information.
self.edgeMobileClient.getInfo { (result) in
guard let checkedInfo = result.info else {
print("mimik edge not running?")
return
}
print(mimik edge info: \(checkedInfo))
}
Platform service links
Description
Platform instance service and websocket links, for your microservice configuration.
func platformServiceLink() -> String? {
return self.edgeMobileClient.platformServiceLink()
}
func platformWebSocketServiceLink() -> String? {
return self.edgeMobileClient.platformWebSocketServiceLink()
}
Setting log levels
Description
Configures platform log output. Unified logging system is used and the messages are tagged with [mimik] [module-name] and then [info] [error] [fault] [debug].
import MIMIKEdgeMobileClient
MIMIKLog.setLoggingLevelTo(level: .debug, subsystem: .third_party)
Need more help?
Feel free to contact us on Stack Overflow or send us a question via our support page if you have any questions.