首页 > 解决方案 > 在 iOS CloudKit 中,是否有办法在数据传输启动后中止/取消?

问题描述

我的 iOS 应用程序在 iCloud Drive 中读取和写入文本和二进制数据。当一个传输完成时,我启动下一个。如果转移在两分钟内没有完成,我会问用户他或她是想再等一会儿还是放弃。众所周知,iCloud 传输有时需要很长时间,或者挂起。

如果用户想放弃,我处理云文档并将其设置为空。之后,用户可以跳转到另一个屏幕。我本来想先中止转移,但不知道该怎么做。

我遇到以下形式的崩溃,我怀疑这可能是相关的(这是在 Xamarin 中,但毫无疑问,这个问题也适用于 Swift/ObjectiveC):

ObjCRuntime.RuntimeException: Failed to marshal the Objective-C object 0x281046140 (type: MyApp_iOS_Cloud_CloudTextDocument). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'MyApp.iOS.Cloud.CloudTextDocument' does not have a constructor that takes one IntPtr argument). Additional information: Selector: contentsForType:error: Method: MyApp.iOS.Cloud.CloudTextDocument:ContentsForType (string,Foundation.NSError&) at (wrapper managed-to-native) ObjCRuntime.Messaging.objc_msgSendSuper(intptr,intptr,intptr,long,intptr) at UIKit.UIDocument.Save (Foundation.NSUrl url, UIKit.UIDocumentSaveOperation saveOperation, UIKit.UIOperationHandler completionHandler)

可能是在我摆脱文档后,传输最终尝试继续,但发现文档已经消失,导致崩溃。

有没有办法中止转移,或者我可以使用其他方法吗?

标签: ioscloudkitfile-transfericloud-drive

解决方案


推荐阅读