Implementation
The implementation shows an example of how you can add MetaMap SDK using a MetaMap button or MetaMap method.
In the last part, callback methods that are called when verification is successfully completed or when verifications is canceled. In order to learn whether the verification was successfully completed or cancelled we need to set a callback.
- Start verification -
showMetaMapFlow
To start verification you need to use this method In order to make this work you need to set your ownYOUR_CLIENT_ID
andYOUR_FLOW_ID
. You can find them in the Metamap Dashboard, for more details please check the Set Up An Account section. - Verification is completed -
verificationSuccess
when the verification is completed the method will be called - Verification is Cancelled -
verificationCancelled
when the verification is canceled the method will be called
import UIKit
import MetaMapSDK
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupMetaMapButton()
}
private func setupMetaMapButton() {
// Initialize the MetaMap button
let metaMapButton = MetaMapButton()
metaMapButton.frame = CGRect(
x: 20,
y: view.frame.height / 2 - 25,
width: view.frame.width - 40,
height: 50
)
// Set up button action
metaMapButton.addTarget(self, action: #selector(metaMapButtonTapped), for: .touchUpInside)
// Add button to the view
view.addSubview(metaMapButton)
// Set delegate to receive results from MetaMap
MetaMapButtonResult.shared.delegate = self
}
@objc private func metaMapButtonTapped() {
// Present MetaMap verification flow
MetaMap.shared.showMetaMapFlow(
clientId: "YOUR_CLIENT_ID",
flowId: "YOUR_FLOW_ID",
metadata: [:]
)
}
}
// MARK: - MetaMapButtonResultDelegate
extension ViewController: MetaMapButtonResultDelegate {
func verificationSuccess(identityId: String?, verificationID: String?) {
print("✅ MetaMap Verification Succeeded")
print("🔹 Identity ID: \(identityId ?? "nil")")
print("🔹 Verification ID: \(verificationID ?? "nil")")
}
func verificationCreated(identityId: String?, verificationID: String?) {
print("🆕 MetaMap Verification Created")
print("🔹 Identity ID: \(identityId ?? "nil")")
print("🔹 Verification ID: \(verificationID ?? "nil")")
}
func verificationCancelled(identityId: String?, verificationID: String?) {
print("❌ MetaMap Verification Cancelled")
print("🔹 Identity ID: \(identityId ?? "nil")")
print("🔹 Verification ID: \(verificationID ?? "nil")")
}
}
#import "ViewController.h"
#import <MetaMapSDK/MetaMapSDK.h>
@interface ViewController () <MetaMapButtonResultDelegate>
@property (nonatomic, strong) MetaMapButton *metaMapButton;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// MARK: - Initialize MetaMap button
self.metaMapButton = [[MetaMapButton alloc] init];
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;
// Set action for button tap
[self.metaMapButton addTarget:self
action:@selector(metaMapButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
// Add button to the view
[self.view addSubview:self.metaMapButton];
// Set delegate to receive MetaMap results
[MetaMapButtonResult shared].delegate = self;
}
// MARK: - MetaMap Action
- (void)metaMapButtonAction:(UIButton *)sender {
// Start MetaMap verification flow
[MetaMap.shared showMetaMapFlowWithClientId:@"YOUR_CLIENT_ID"
flowId:@"YOUR_FLOW_ID"
metadata:@{}];
}
// MARK: - MetaMapButtonResultDelegate
- (void)verificationSuccessWithIdentityId:(NSString *)identityId
verificationID:(NSString *)verificationID {
NSLog(@"✅ Verification Succeeded");
NSLog(@"🔹 Identity ID: %@", identityId);
NSLog(@"🔹 Verification ID: %@", verificationID);
}
- (void)verificationCancelledWithIdentityId:(NSString *)identityId
verificationID:(NSString *)verificationID {
NSLog(@"❌ Verification Cancelled");
NSLog(@"🔹 Identity ID: %@", identityId);
NSLog(@"🔹 Verification ID: %@", verificationID);
}
@end
In order to make this work you need to set your own CLIENT_ID
and FLOW_ID
. You can find them in the Metamap Dashboard, for more details please check this section.
Congratulations! At this stage, you are already able to start the Metamap SDK and have your first verification.
Updated 7 days ago