I get the following error on my @main thread "This method should not be called on the main thread as it may lead to UI unresponsiveness."
The vast majority of the time the UI responsiveness is fine however it does sometimes become unresponsive. I've noticed it often becomes unresponsive when a link that navigates out of the app is tapped when Link() is used.
I think that it is caused by the Google Admob code that was added.
Here is my code:
import SwiftUI
import BackgroundTasks
import GoogleMobileAds
import UserNotifications
@main
struct Test_ProjectApp: App {
init(){
GADMobileAds.sharedInstance().start(completionHandler: nil)
let isNotificationsEnabled = UserDefaults.standard.bool(forKey: "isNotificationsEnabled")
if isNotificationsEnabled {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if granted {
print("Notifications permission granted.")
exampleNotification()
} else {
print("Notifications permission denied because: \(error?.localizedDescription ?? "unknown error").")
}
}
}
}
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL(perform: { url in
})
}
}
}
Is this an okay place to call the method or should it be done differently?
it's a bug by Apple, and Apple was also aware of this bug. It has already been fixed in XCode 14.3.