Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIDocumentInteractionControllerDelegate EXC\u错误访问Swift_Ios_Swift_Exc Bad Access_Uidocumentinteraction - Fatal编程技术网

Ios UIDocumentInteractionControllerDelegate EXC\u错误访问Swift

Ios UIDocumentInteractionControllerDelegate EXC\u错误访问Swift,ios,swift,exc-bad-access,uidocumentinteraction,Ios,Swift,Exc Bad Access,Uidocumentinteraction,我当前正在尝试使用UIDocumentInteractionController实例打开另一个应用程序的文件。一切正常(例如,显示选项对话框,打开应用程序),但当应用程序切换实际发生时,我收到的是EXC_BAD_访问,而不是didFinishSendingToApplication:delegate回调。在我将这段代码从Objective-C移植到Swift之前,一切正常。 你知道这里出了什么问题吗 self.documentInteractionController = UIDocumentI

我当前正在尝试使用UIDocumentInteractionController实例打开另一个应用程序的文件。一切正常(例如,显示选项对话框,打开应用程序),但当应用程序切换实际发生时,我收到的是EXC_BAD_访问,而不是didFinishSendingToApplication:delegate回调。在我将这段代码从Objective-C移植到Swift之前,一切正常。 你知道这里出了什么问题吗

self.documentInteractionController = UIDocumentInteractionController(URL: self.fileURL)
self.documentInteractionController!.UTI = "net.whatsapp.movie"
self.documentInteractionController!.delegate = self
以下是我可以获得的所有堆栈跟踪(崩溃实际上发生在主函数中,因此我无法获得更多…):

*thread#1:tid=0x12ef7e,0x0000000182dd18c8 CoreFoundation`CFStringCreateCopy+36,queue='com.apple.main thread',stopreason=EXC#u BAD#访问(代码=1,地址=0x0)
*帧#0:0x0000000182dd18c8 CoreFoundation`CFStringCreateCopy+36
帧#1:0x0000000101df09d8 libswiftCore.dylib` Swift.String.init(Swift.String.Type)的函数签名专门化(_cocoaString:Swift.AnyObject)->Swift.String+108
帧#2:0x0000000101dd45b0 libswiftCore.dylib`Swift.String.init(Swift.String.Type)(_cococoString:Swift.AnyObject)->Swift.String+24
帧#3:0x0000000100253814 MyApp`@objc MyApp.MyViewController.documentInteractionController(MyApp.MyViewController)(ObjectiveC.UIDocumentInteractionController,didEndSendingToApplication:Swift.String)->()+84位于MyViewController处。Swift:0
帧#4:0x0000000183dedf9c基础`u#n线程性能模板+372
帧#5:0x0000000182ea4240 CoreFoundation`\uuuu CFRUNLOOP\u正在调用\u OUT\u到\u A\u SOURCE0\u PERFORM\u函数\uu24
帧#6:0x0000000182ea34e4 CoreFoundation`\uu CFRunLoopDoSources0+264
帧#7:0x0000000182ea1594 CoreFoundation`\uu CFRunLoopRun+712
帧#8:0x0000000182dcd2d4 CoreFoundation`CFRunLoopRunSpecific+396
帧#9:0x000000018c5e36fc GraphicsServices`GSEventRunModal+168
帧#10:0x0000000187992fac UIKit`UIApplicationMain+1488
帧#11:0x00000001000c6374 MyApp`main(argc=1,argv=0x000000016fdf79c0)+124位于main处。m:33
帧#12:0x0000000194d8ea08 libdyld.dylib`start+4

我遇到了同样的问题,花了几天时间试图解决这个问题

我最终发现,此错误的根本原因是在类中实现了
func documentInteractionController(控制器:UIDocumentInteractionController,didEndSendingToApplication应用程序:String)

我删除了此功能,改用
将开始向应用程序发出指示
,应用程序在切换应用程序时不会崩溃


在运行iOS 7.1和iOS 8.3的真实设备上测试。仅供参考真正的问题是SDK上的代理签名错误。而不是
documentInteractionController(controller: UIDocumentInteractionController, didEndSendingToApplication application: String)
你应该使用

documentInteractionController(controller: UIDocumentInteractionController, didEndSendingToApplication application: String?)
请不要选择最后一个
,这表示应用程序参数可以是
nil
,它总是这样

您应该对
willbegindingtoapplication
调用执行相同的操作,因为它也可以有
nil
应用程序参数

可以安全地忽略关于不同于协议预期的可选性的警告

documentInteractionController(controller: UIDocumentInteractionController, didEndSendingToApplication application: String?)