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

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

Code Block
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? 🙈
I second that. Would love to know...
I am working on a cross platform app and using the app lifecycle across all platforms would be great. Since I can’t do that, my current plan is to keep using the new lifecycle on macOS, but fall back to iOS 13 way on iOS until there is a way to accept CloudKit shares in the new lifecycle.

In your SceneDelegate...

import CloudKit

then add this func...

func windowScene(_ windowScene: UIWindowScene, userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata) {
        // Call your function that accepts the share and pass it the metadata that is passed in.

        acceptShare(with: cloudKitShareMetadata)
}

CloudKit share acceptance still requires a UIWindowSceneDelegate on iOS.

Can try this approach ----

Keep SwiftUI lifecycle

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Add SceneDelegate

import UIKit
import CloudKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    func windowScene(
        _ windowScene: UIWindowScene,
        userDidAcceptCloudKitShareWith metadata: CKShare.Metadata
    ) {
        acceptShare(with: metadata)
    }
}

Register it in Info.plist

UISceneDelegateClassName = SceneDelegate
How to accept CloudKit shares with the new SwiftUI app lifecycle?
 
 
Q