10 C
New York
Sunday, March 30, 2025

xcode – SwiftUI app freezes on iOS 18 with Swift 6 after ATT permission dialog clicked – thread assertion difficulty


My app is used to construct with Swift 6 and it really works completely positive. Nevertheless, since I’m utilizing Google AdMob for monetization, I’ve to implement the App Monitoring Transparency (ATT) immediate dialog at the beginning of the app.

That is my present implementation:

import SwiftUI
import GoogleMobileAds
import AppTrackingTransparency

class AppDelegate: UIResponder, UIApplicationDelegate {
    
    func software(_ software: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Initialize Cellular Adverts SDK
        MobileAds.shared.begin(completionHandler: nil)
        
        // Request ATT authorization after a delay
        DispatchQueue.foremost.asyncAfter(deadline: .now() + 1.0) {
            self.requestIDFA()
        }
        
        return true
    }
    
    func requestIDFA() {
        ATTrackingManager.requestTrackingAuthorization { standing in
            // Deal with authorization standing
            change standing {
            case .approved:
                print("ATT: Person approved monitoring")
            case .denied:
                print("ATT: Person denied monitoring")
            case .restricted:
                print("ATT: Monitoring is restricted")
            case .notDetermined:
                print("ATT: Person has not made a alternative")
            @unknown default:
                print("ATT: Unknown standing")
            }
        }
    }
}


@foremost
struct MyApp: App {
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var physique: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

I examined with iOS 16 and 17, and it really works as anticipated. However once I examined on iOS 18 emulator, the immediate seems, click on on the Permit or Not Permit, and it froze. The consumer alternative continues to be registered as ATT: Person approved monitoring present within the log (and after exit the app and open once more, the log nonetheless present the right consumer ATT alternative).

The issue is relating to string assertion difficulty. For instance:

Thread 2 Queue : com.apple.root.default-qos (concurrent)

#0  0x00000001023e4214 in _dispatch_assert_queue_fail ()
#12 0x00000001025afb38 in _pthread_wqthread ()

My resolution: After making an attempt to debug, I came upon that I solely want to change from Swift 6 to Swift 5. And the appliance works once more.

My Request: My request is that I nonetheless need to construct the app with Swift 6 (for future proof functions), how can I accomplish that? Thanks~

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles