iOS

Add the MetaMap button to your iOS app.

MetaMap iOS Usage Guide

The following describes how to install and use the MetaMap iOS SDK for your application.

iOS Demo App

You can go to GitHub and download the MetaMap iOS demo app

Requirements and size

iOS 12+
Xcode 12.0
Swift 5.0

SDK compiled size: ~10MB

Source (in project files): 55MB

Add the MetaMap SDK

Install Using CocoaPods

Create a Podfile and add the pod MetaMap-Global-ID-SDK:

pod 'MetaMap-Global-ID-SDK'

Update your pods from the terminal

pod install

Note The following dependencies will be automatically installed with the pod MetaMap-Global-ID-SDK:

  • Starscream
  • SocketIO

Implement MetaMap in Your App

Add the MetaMap button to your App.

IMPORTANT Info.plist
Add the following permissions to capture video, access the photo gallery, and access the microphone for the voiceliveness feature.

<key>NSCameraUsageDescription</key>
<string>MetaMap needs access to your Camera</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>MetaMap needs access to your media library</string>
<key>NSMicrophoneUsageDescription</key>
<string>MetaMap needs access to your Microphone</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>MetaMap will use your location information to provide best possible verification experience.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>MetaMap will use your location information to provide best possible verification experience.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>MetaMap will use your location information to provide best possible verification experience.</string>

Set the following parameters for your application:

ParameterTypeRequiredExample
metaMapButton.titlestringRequiredmetaMapButton.title = "Verify Me"
metaMapButton.textColorUIColorOptionalmetaMapButton.textColor = .white
metaMapButton.buttonColorUIColorOptionalmetaMapButton.buttonColor = .black
Metadata
Note Go to the Metadata section
to learn more about using metadata
@Nullable MetadataOptional

Note Be sure to initialize the MetaMap button before use.

Swift

import UIKit
import MetaMapSDK

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupMetaMapButton()
    }

    private func setupMetaMapButton() {

      //init button
      let metaMapButton = MetaMapButton()

      //add button action
            metaMapButton.addTarget(self, action: #selector(self.metaMapButtonAction), for: .touchUpInside)

      //set view of button
            metaMapButton.frame = CGRect(x: 20, y: self.view.frame.size.height/2 - 50, width: view.frame.size.width - 40, height: 50)

      //add button to yours view
      view.addSubview(metaMapButton)

      //set delegate to get result
      MetaMapButtonResult.shared.delegate = self

    }

      @objc private func metaMapButtonAction() {
    //set params to showMetaMapFlow
    MetaMap.shared.showMetaMapFlow(clientId: "YOUR_CLIENT_ID",
                flowId: "YOUR_FLOW_ID",
                metadata: ["key1": "value1", "key2": 123])
    }
}

//MARK: MetaMapButtonResultDelegate
extension ViewController: MetaMapButtonResultDelegate {

    func verificationSuccess(identityId: String?, verificationID: String?) {
        print("MetaMap Verification Success \(identityId)")
    }

    func verificationCancelled() {
        print("MetaMap Verification Cancelled")
    }
}

SwiftUI


import SwiftUI
import MetaMapSDK
import UIKit

struct ContentView: View {
    var body: some View {
        VStack {
            ZStack {
//MARK: MetaMapDelegateObserver
                MetaMapDelegateObserver { identityId, verificationId in
                    print("\(identityId), \(verificationId)")
                } cancelled: {
                    print("cancelled")
                }
                HStack {
                    Button(action: {
                        MetaMap.shared.showMetaMapFlow(clientId: "YOUR_CLIENT_ID", flowId: "YOUR_FLOW_ID", metadata: ["key1": "value1", "key2": 123])
                    }) {
                        Text("press me")
                    }
                }
            }
        }
    }
}

struct MetaMapDelegateObserver: UIViewControllerRepresentable {
    let vc = MatiViewController()
    public func makeUIViewController(context: Context) -> MatiViewController {
        return vc
    }
    
    public func updateUIViewController(_ uiViewController: MatiViewController, context: Context) {}
    
    var success: (_ identityId: String?, _ verificationId: String?) -> Void
    var cancelled: () -> Void
    
    public func makeCoordinator() -> Coordinator {
        Coordinator(success: success, cancelled: cancelled)
    }
    
    public  class Coordinator: NSObject, MetaMapButtonResultDelegate {
        public  func verificationSuccess(identityId: String?, verificationID: String?) {
            success(identityId, verificationID)
        }
        
        public  func verificationCancelled() {
            cancelled()
        }
        
        var success: (_ identityId: String?, _ verificationId: String?) -> Void
        var cancelled: () -> Void
        
        init(success: @escaping (_ identityId: String?, _ verificationId: String?) -> Void, cancelled: @escaping () -> Void) {
            self.success = success
            self.cancelled = cancelled
            super.init()
            MetaMapButtonResult.shared.delegate = self
        }
    }
}

class MetaMapViewController: UIViewController {}

Objective-C



    #import "ViewController.h"
    #import <MetaMapSDK/MetaMapSDK.h>

    @interface ViewController () <MetaMapButtonResultDelegate>

    @property (nonatomic, strong) MetaMapButton *metaMapButton;

    @end

    @implementation ViewController

      - (void)viewDidLoad {
          [super viewDidLoad];

          //init button
          self.metaMapButton = [[MetaMapButton alloc] init];

          //add action to yours button
            [self.metaMapButton addTarget:self action:@selector(metaMapButtonAction:) forControlEvents:UIControlEventTouchUpInside];

          //set view of button
          self.metaMapButton.frame = CGRectMake(20, self.view.frame.size.height/2 - 25, self.view.frame.size.width - 40, 50);
          self.metaMapButton.center = self.view.center;

           //add button to yours view
          [self.view addSubview:self.metaMapButton];

          //set delegate to get result
          [MetaMapButtonResult shared].delegate = self;
      }

      //add showMetaMapFlow function with YOURS parameters
      -(void)metaMapButtonAction:(UIButton *) sender{
          [MetaMap.shared showMetaMapFlowWithClientId:@"YOUR_CLIENT_ID" flowId:@"YOUR_FLOW_ID"  metadata:@{@"key1":@"value"}];
    }

    #pragma mark - MetaMapButtonResultDelegate
    
      -(void)verificationSuccessWithIdentityId:(NSString *)identityId, verificationID(NSString *) {
          NSLog(@"Success: [email protected]", identityId);
      }

      - (void)verificationCancelled {
          NSLog(@"Cancelled");
      }

    @end;

Metadata Usage

Metadata is an additional optional parameter that you can receive using a webhook after passing verification. The metadata is also displayed in the verification on the Dashboard.

Metadata: Set the Language

You can use metadata to set specific parameters, including setting your default language and to hide language settings from users.

key: fixedLanguage
value: locale code of language

For instance, to set the language code for Spain to Spanish, we would set the fixedLanguage parameter to es"

Example: Set the Language Code for Spain

Swift, SwiftUI

metadata: ["fixedLanguage": "es"]

Metadata: Set the Button Color

You can use metadata to set the color of the main buttons in your flow.

To set the background color of the button, use the following parameter:

key: buttonColor
value: hexColor

Example

Swift, SwiftUI

metadata: ["buttonColor": "#C0C8D1"]

To set the title color of the button:

key: buttonTextColor
value: hexColor

Example

Swift, SwiftUI

metadata: ["buttonTextColor": "#C0C8D1"]

Did this page help you?