iOS Embed(Swift)
1
//
2
// ARMODUtility.swift
3
// ARMODStore
4
//
5
// Created by Phantomsxr.com on 2021/5/2.
6
//
7
8
import Foundation
9
10
11
class ARMODUtility {
12
public static var armod = ARMOD()
13
14
static func getStatusBarHeight() -> CGFloat {
15
var heightToReturn: CGFloat = 0.0
16
for window in UIApplication.shared.windows {
17
if let height = window.windowScene?.statusBarManager?.statusBarFrame.height, height > heightToReturn {
18
heightToReturn = height
19
}
20
}
21
print(heightToReturn)
22
return heightToReturn
23
}
24
25
static func initARMOD(){
26
27
let configJson = convertPlistToJson(plistName: "AppConfig")
28
armod.registerAPIforNativeCalls(ARMODCallback())
29
armod.initARMOD(configJson)
30
armod.setUIInterfaceOrientation(.portrait)
31
armod.loadAndShowView()
32
33
}
34
static func launchARById(id:String) {
35
initARMOD()
36
armod.fetchProject(id)
37
}
38
39
static func launchARScan() {
40
initARMOD()
41
armod.fetchProjectByImage()
42
}
43
44
static func convertPlistToJson(plistName:String) -> String {
45
if let url = Bundle.main.url(forResource:plistName, withExtension: "plist") {
46
do {
47
let data = try Data(contentsOf:url)
48
let dict = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as! [String:Any]
49
let jsonData = try JSONSerialization.data(withJSONObject: dict , options: .prettyPrinted)
50
return String(data: jsonData, encoding: String.Encoding.utf8) ?? ""
51
} catch {
52
print(error)
53
}
54
}
55
return ""
56
}
57
}
58
Copied!
1
//
2
// ARMODCallback.swift
3
// ARMOD Store
4
//
5
// Created by phantomsxr.com on 2021/2/15.
6
//
7
8
import Foundation
9
import UIKit
10
import SwiftUI
11
12
class ARMODCallback: UIResponder,NativeCallsProtocol {
13
func onARMODExit() {
14
15
}
16
17
func packageSizeMoreThanPresetSize(_ currentSize: Float, preset presetSize: Float) {
18
showAlert(title: "Tips", buttonTitle: "Continue", msg: String(format: "Need to download %.2f", currentSize),completionHandler: {
19
ARMODUtility.armod.continueToDownloadARExperience()})
20
}
21
22
fileprivate let loadingView = UIHostingController(rootView: LoadingView())
23
public static let arView = UIHostingController(rootView: ARView(statusBarHeight: ARMODUtility.getStatusBarHeight()))
24
25
func throwException(_ message: String!, errorCode code: Int32) {
26
print(String(format: "[ERROR]:%@,code:%d", message,code))
27
showAlert(title: "ERROR", buttonTitle: "Ok", msg: String(format: "[ERROR]:%@,code:%d", message,code),completionHandler: {
28
ARMODUtility.armod.unloadAndHideView()})
29
}
30
31
32
func addLoadingOverlay() {
33
let controller = ARMODUtility.armod.getController()
34
let view = controller?.view
35
36
view!.addSubview(loadingView.view)
37
controller?.addChild(loadingView)
38
loadingView.didMove(toParent: controller)
39
loadingView.view.backgroundColor = UIColor.clear
40
loadingView.view.translatesAutoresizingMaskIntoConstraints = false
41
loadingView.view.topAnchor.constraint(equalTo: view!.topAnchor).isActive = true
42
loadingView.view.bottomAnchor.constraint(equalTo: view!.bottomAnchor).isActive = true
43
loadingView.view.leftAnchor.constraint(equalTo: view!.leftAnchor).isActive = true
44
loadingView.view.rightAnchor.constraint(equalTo: view!.rightAnchor).isActive = true
45
46
view!.addSubview(ARMODCallback.arView.view)
47
controller?.addChild(ARMODCallback.arView)
48
ARMODCallback.arView.didMove(toParent: controller)
49
ARMODCallback.arView.view.backgroundColor = UIColor.clear
50
ARMODCallback.arView.view.translatesAutoresizingMaskIntoConstraints = false
51
ARMODCallback.arView.view.topAnchor.constraint(equalTo: view!.topAnchor).isActive = true
52
ARMODCallback.arView.view.bottomAnchor.constraint(equalTo: view!.bottomAnchor).isActive = true
53
ARMODCallback.arView.view.leftAnchor.constraint(equalTo: view!.leftAnchor).isActive = true
54
ARMODCallback.arView.view.rightAnchor.constraint(equalTo: view!.rightAnchor).isActive = true
55
56
}
57
58
59
func updateLoadingProgress(_ progress: Float) {
60
}
61
62
func removeLoadingOverlay() {
63
loadingView.removeFromParent()
64
loadingView.dismiss(animated: true, completion: nil)
65
loadingView.view.removeFromSuperview()
66
}
67
68
func deviceNotSupport() {
69
print("Device not support")
70
}
71
72
func sdkInitialized() {
73
print("SDK Initialized")
74
75
}
76
77
func openBuilt(inBrowser url: String!) {
78
print("")
79
}
80
81
func recognitionStart() {
82
83
}
84
85
func recognitionComplete() {
86
print("")
87
}
88
89
func tryAcquireInformation(_ opTag: String!) -> String! {
90
return ""
91
}
92
93
94
//https://stackoverflow.com/a/60562200
95
@objc private func showAlert(title:String,buttonTitle:String,msg:String,completionHandler:@escaping()->Void){
96
let alert = UIAlertController(title: title, message: msg, preferredStyle: .alert)
97
let cancelAction = UIAlertAction(title: buttonTitle, style: .cancel) { (action) in
98
completionHandler()
99
}
100
alert.addAction(cancelAction)
101
DispatchQueue.main.async {
102
ARMODUtility.armod.getController()?.present(alert, animated: true, completion: nil)
103
}
104
}
105
}
106
Copied!
Last modified 1mo ago
Copy link