We will be requiring two Swift files:
ARPlugin.swift
1import Capacitor
2
3@objc(ARPlugin)
4public class ARPlugin: CAPPlugin {
5 @objc func open(_ call: CAPPluginCall) {
6 DispatchQueue.main.async {
7 let arViewController: ARViewController = UIStoryboard(name: "AugmentedReality", bundle: nil).instantiateInitialViewController()!
8 arViewController.eventListeners = self.eventListeners!
9 self.bridge?.viewController?.present(arViewController, animated: true, completion: nil)
10 }
11 }
12}
This file is where the methods that will later be executable from the TypeScript code are written.
ARPlugin.m
1#import <Capacitor/Capacitor.h>
2
3CAP_PLUGIN(ARPlugin, "ARPlugin", CAP_PLUGIN_METHOD(open, CAPPluginReturnNone);)
These methods are then registered with Capacitor.
In the Web App, the plugin is then used as follows:
1import { registerPlugin } from '@capacitor/core';
2
3const ARPlugin = registerPlugin('ARPlugin')
4
5await ARPlugin.open()