Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to accept CloudKit shares with the new SwiftUI app lifecycle?

In the iOS 13 world, I had code like this:

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
        func windowScene(_ windowScene: UIWindowScene, userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata) {
                // do stuff with the metadata, eventually call CKAcceptSharesOperation
        }
}

I am migrating my app to the new SwiftUI app lifecycle, and can’t figure out where to put this method. It used to live in AppDelegate pre-iOS13, and I tried going back to that, but the AppDelegate version never gets called.

There doesn’t seem to be a SceneDelegateAdaptor akin to UIApplicationDelegateAdaptor available, which would provide a bridge to the old code.

So, I’m lost. How do I accept CloudKit shares with SwiftUI app lifecycle? 🙈

like image 369
Jaanus Avatar asked Dec 05 '25 08:12

Jaanus


1 Answers

You can still use AppDelegate with SwiftUI's new life-cycle until Apple releases APIs to handle this natively in SwiftUI’s App Life-cycle.

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        return true
    }
}

@main
struct MyApp: App {

    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Read this for more

like image 199
Ishmeet Avatar answered Dec 09 '25 13:12

Ishmeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!