Accept CKShare with the SwiftUI lifecycle.

Hi,
I want to implement the  
Code Block
func windowScene(_ windowScene: UIWindowScene, userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata)

method in my SwiftUI lifecycle app. I already used
Code Block
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

and added the AppDelegate:
Code Block
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata) {
        print("CK Share accepted")
    }
}

Without any success. No "CK Share accepted" in the log.
I also tried it with the Scene Delegate and the
Code Block swift
func windowScene(_ windowScene: UIWindowScene, userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata)

again no luck.

I've tried literally everything. The link is working because if I open the share on a sample that uses the UIKit Lifecycle it works correctly.

Did I miss anything, or is this a bug with the SwiftUI Lifecycle and UIApplicationDelegateAdaptor?

Take care,
David

Good question. Did you manage to "send" a share to anyone using SwiftUI? Even this is impossible for me ... (And everything works fine in UIKit for me).
Hi Kevin,
Interestingly creating the share and the SharingController wasn't too difficult. Other than that the title of the SharingController sometimes just being "Untitled" it works as expected. No idea why the title configuration is sometimes not filled in correctly.
I switched back to UIKit Lifecycle because it is just so frustrating seeing how little the SwiftUI lifecycle can do right now... I hope they will add these methods natively in future releases without the need of DelegateAdaptors.

Take care,
David

FWIW I am having the same problem. -- Able to send share SwiftUI + UICloudSharingController -- Receive share on iPad -- Tap share link, and app opens (!)

But the App delegate method is not called.

This is with Xcode 12.5, iPadOS 14.5.1

Hopefully this may help ...

I started with the Apple sample at: https://github.com/apple/cloudkit-sample-sharing

  • Added SceneDelegate
  • Setup SceneDelegate in AppDelegate and Plist
  • Added SceneDelegate method for userDidAcceptCloudKitShareWith

The method is now being called when the share link is tapped.

Accept CKShare with the SwiftUI lifecycle.
 
 
Q