import Foundation
import UIKit
import SwiftUI
class ARMODCallback: UIResponder,NativeCallsProtocol {
func onARMODExit() {
}
func packageSizeMoreThanPresetSize(_ currentSize: Float, preset presetSize: Float) {
showAlert(title: "Tips", buttonTitle: "Continue", msg: String(format: "Need to download %.2f", currentSize),completionHandler: {
ARMODUtility.armod.continueToDownloadARExperience()})
}
fileprivate let loadingView = UIHostingController(rootView: LoadingView())
public static let arView = UIHostingController(rootView: ARView(statusBarHeight: ARMODUtility.getStatusBarHeight()))
func throwException(_ message: String!, errorCode code: Int32) {
print(String(format: "[ERROR]:%@,code:%d", message,code))
showAlert(title: "ERROR", buttonTitle: "Ok", msg: String(format: "[ERROR]:%@,code:%d", message,code),completionHandler: {
ARMODUtility.armod.unloadAndHideView()})
}
func addLoadingOverlay() {
let controller = ARMODUtility.armod.getController()
let view = controller?.view
view!.addSubview(loadingView.view)
controller?.addChild(loadingView)
loadingView.didMove(toParent: controller)
loadingView.view.backgroundColor = UIColor.clear
loadingView.view.translatesAutoresizingMaskIntoConstraints = false
loadingView.view.topAnchor.constraint(equalTo: view!.topAnchor).isActive = true
loadingView.view.bottomAnchor.constraint(equalTo: view!.bottomAnchor).isActive = true
loadingView.view.leftAnchor.constraint(equalTo: view!.leftAnchor).isActive = true
loadingView.view.rightAnchor.constraint(equalTo: view!.rightAnchor).isActive = true
view!.addSubview(ARMODCallback.arView.view)
controller?.addChild(ARMODCallback.arView)
ARMODCallback.arView.didMove(toParent: controller)
ARMODCallback.arView.view.backgroundColor = UIColor.clear
ARMODCallback.arView.view.translatesAutoresizingMaskIntoConstraints = false
ARMODCallback.arView.view.topAnchor.constraint(equalTo: view!.topAnchor).isActive = true
ARMODCallback.arView.view.bottomAnchor.constraint(equalTo: view!.bottomAnchor).isActive = true
ARMODCallback.arView.view.leftAnchor.constraint(equalTo: view!.leftAnchor).isActive = true
ARMODCallback.arView.view.rightAnchor.constraint(equalTo: view!.rightAnchor).isActive = true
}
func updateLoadingProgress(_ progress: Float) {
}
func removeLoadingOverlay() {
loadingView.removeFromParent()
loadingView.dismiss(animated: true, completion: nil)
loadingView.view.removeFromSuperview()
}
func deviceNotSupport() {
print("Device not support")
}
func sdkInitialized() {
print("SDK Initialized")
}
func openBuilt(inBrowser url: String!) {
print("")
}
func recognitionStart() {
}
func recognitionComplete() {
print("")
}
func tryAcquireInformation(_ opTag: String!) -> String! {
return ""
}
@objc private func showAlert(title:String,buttonTitle:String,msg:String,completionHandler:@escaping()->Void){
let alert = UIAlertController(title: title, message: msg, preferredStyle: .alert)
let cancelAction = UIAlertAction(title: buttonTitle, style: .cancel) { (action) in
completionHandler()
}
alert.addAction(cancelAction)
DispatchQueue.main.async {
ARMODUtility.armod.getController()?.present(alert, animated: true, completion: nil)
}
}
}