我有以下代码来将UICloudSharingController导入SwiftUI,但当第一次集成时它只显示一个永远不停止的活动指示器,然后第二次(通过.sheet)呈现时,就没有活动指示器了。第一次出现时,我可以看到右上角带有活动指示器的关闭按钮。任何反馈都会受到赞赏。
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>) {
}
}