Tutorials
Integrate edgeEngine to iOS- Swift
Prerequisites
1. Make sure you have the latest Xcode version installed.
2. Setup and connect an iOS device to run applications from Xcode.
Important: edgeEngine cannot be used with iOS simulators, it needs real devices.
Step 1. Register your project
Important: mimik developer account is required for application registration, platform authorization and microservice deployment.
2. In the mimik developer console, click Create New Project.
3. Enter a Project Name.
4. Upload a logo image if you want to use your own Project Logo.
5. Submit the form with the auto-generated Redirect URI or enter your own.
Important: edgeEngine uses OAuth 2.0 for authentication and a redirect URI is necessary for the process. The standard format of redirect URI is com.<string>://<string>. You can learn more about it here.
Step 2. MIMIKEdgeMobileClient cocoapods installation
EdgeMobileClient iOS wrapper
EdgeMobileClient
This guide explains what you need to know in order to integrate mimik edgeEngine into your iOS project as quickly as possible using a cocoapod wrapper.
CocoaPods Installation
The easiest way to integrate edgeEngine to an iOS application is by adding a EdgeMobileClient wrapper cocoapod to your project with the following additions to your project’s Podfile:
platform: ios, '12.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
Wrapper Features
- Platform startup and shutdown
- Platform authorization using mimik identity services
- Microservice deployment and undeployment
- List of deployed microservices
- Platform instance information
- Setting platform log levels
Wrapper initialization
Description
Import MIMIKEdgeMobileClient module and initialize its instance.
Example Code
import MIMIKEdgeMobileClient
lazy var edgeMobileClient: MIMIKEdgeMobileClient = {
return MIMIKEdgeMobileClient.init()
}()
Platform startup
Description
Platform startup 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.
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 service links
Description
Platform instance service and websocket links, for your microservice configuration.
Example Code
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].
Example Code
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.