I want to show user a alert in case my application stop before creating a window to show root view controller and i want to do this from a worker thread which will be running in a cpp file and will be calling swift file before a UIApplication.shared.delegate is created.So , I want to show a error message to user from worker thread without switching to main thread (without using DispactchQueue.main.sync{code...})
I tried a using a UIAlertController to present it from worker thread but xcode yelled at me to use it to call from main thread.Is there way to show error message to user to let him know to update/make changes in his system before start app??
.swift file
import UIKit
@objc class AlertPopUpInWin:NSObject{
@objc func AlertPopUp(labelText:NSString){
print(labelText)
let delegate = UIApplication.shared.delegate
let window = delegate?.window
let vc = window?!.rootViewController as! ViewController
let alert = UIAlertController(title: "hello", message: labelText as String, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
vc.present(alert, animated: true)
}
}
.cpp file - to call AlertPopUP() function from cpp
#include "AlertPopUpDailog.hpp"
#include <iostream>
#include "SwiftWrapper.h"
#include "thread"
#include <cstdlib>
using namespace std;
void AlertPopUpDailog::UpdateAlertDailogInWorkerThread()
{
std::thread t1(AlertPopUpDailog::SwiftFuncCaller);
t1.detach();
}
void AlertPopUpDailog::SwiftFuncCaller()
{
char* alertText = "Alert - hello";
SwiftWrapper::AlertPopUpSwiftWrapper(alertText);
}