Hi OOper,
Thank you for your suggestion about using Life Cycle as UIKit App Delegate. I will try it.
On another hand, I found a way to get a UIViewController object from ContentView.swift file, like the code below. Is this solution Ok? or there will be issue?
Thank you!
import SwiftUI
import MoPubSDK
struct ContentView: View {
var body: some View {
return
Text("Hello, world!")
.padding()
.onAppear(){
// for MoPub: Check whether you must show the consent dialog
let shouldShow = MoPub.sharedInstance().shouldShowConsentDialog;
// for MoPub: Start loading the consent dialog. This call fails if the user has opted out of ad personalization
let myUIViewController : UIViewController = (UIApplication.shared.windows.first?.rootViewController)!
MoPub.sharedInstance().loadConsentDialog(){ a in
MoPub.sharedInstance().showConsentDialog(from: myUIViewController, completion: nil)
}
}
}
}