UICloudSharingController shows infinite activity indicatory in Xcode 11

一个人想着一个人 提交于 2020-01-14 09:32:12

问题


I have the following code to import the UICloudSharingController into swift UI but when integrated the first time up it just shows an activity indicator that never stops and then the second time it is presented (via .sheet), there is no activity indicator. The first time up I can see the close button to the top right corder with activity indicator. Any feedback would be appreciated.

struct CloudSharingController: UIViewControllerRepresentable {
    typealias UIViewControllerType = UICloudSharingController

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    class Coordinator: NSObject, UICloudSharingControllerDelegate {
        func cloudSharingController(_ csc: UICloudSharingController, failedToSaveShareWithError error: Error) {
            print("asdf")

        }

        func itemTitle(for csc: UICloudSharingController) -> String? {
            return "item title for sharing TTT"
        }

        var parent: CloudSharingController

        init(_ cloudSharingController: CloudSharingController) {
            self.parent = cloudSharingController
        }
    }


    var share: CKShare? = nil
    var container: CKContainer = CKContainer.default()

    var firsTimeBlock: ((UICloudSharingController, @escaping (CKShare?, CKContainer?, Error?) -> Void) -> Void)? = nil

    func makeUIViewController(context: UIViewControllerRepresentableContext<CloudSharingController>) -> CloudSharingController.UIViewControllerType {

        let result: UICloudSharingController!
        if let validFirstBlock = firsTimeBlock {
            return UICloudSharingController(preparationHandler: validFirstBlock)
        } else if let validShare = self.share {
            return UICloudSharingController(share: validShare,
                                            container: container)
        } else {
            fatalError()
        }
        result.availablePermissions = [.allowReadWrite]
//        result.popoverPresentationController?.sourceView = AccountsView
        result.delegate = context.coordinator

        return result
    }

    func updateUIViewController(_ uiViewController: CloudSharingController.UIViewControllerType, context: UIViewControllerRepresentableContext<CloudSharingController>) {

    }
}

回答1:


I found a work around which could be found in here:

https://gist.github.com/arashkashi/bcffde1e35c7e406de52d9dff0127d41

The solution in brief includes a view controller wrapper which contains an instance of UICloudSharingController as a child view controller.

UICloudSharingController has two initialized one when there is no CKShare and another one where you already have a CKShare pushed to the CloudKit. I observed that the former initializer gives a never ending activity indicator. So What I did I manually pushed the share with no participants and then provided the empty share to the second initialized of UICloudSharingController.

This is the reason why the wrapper controller should have this line:

var share: CKShare? = nil


来源:https://stackoverflow.com/questions/57310673/uicloudsharingcontroller-shows-infinite-activity-indicatory-in-xcode-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!