【发布时间】:2015-05-08 21:49:11
【问题描述】:
我正在尝试使用UIDocumentInteractionController。我已经检查了我能想到的所有内容,并且所有内容似乎都包含了所有需要的数据。
当调用presentOpenInMenuFromRect(inView:, animated:) 时,返回的 Bool 始终为 false。我的理解是,因为没有任何应用程序支持 UTI。我试过使用扁平的PNG,但仍然没有。有趣的是为什么它不能在我的 iPhone 上运行,它有很多支持通过UIDocumentInteractionController 加载图像的应用程序,但这里是踢球者。在我将项目升级到 Swift 1.2 之前,这段代码运行良好。
我现在忽略了什么吗?我检查了文档,找不到任何我丢失的东西。
注意:我已经在设备和模拟器中对此进行了测试,两者都返回相同的结果。
let image = UIImage(named: "screenshot")
if let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) {
if paths.count > 0 {
if let dirPath = paths[0] as? String {
let path = dirPath.stringByAppendingPathComponent("screenshot.ig") // igo
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), { () -> Void in
if let image = image {
NSFileManager.defaultManager().removeItemAtPath(path, error: nil)
if UIImagePNGRepresentation(image).writeToFile(path, atomically: true) {
}
}
})
if let url = NSURL(fileURLWithPath: path) {
let documentController = UIDocumentInteractionController(URL: url)
documentController.UTI = "com.instagram.photo" // com.instagram.exclusivegram
documentController.annotation = ["InstagramCaption": ""]
if !documentController.presentOpenInMenuFromRect(sender.bounds, inView: self.view, animated: true) {
println("Can't do it")
}
}
}
}
}
【问题讨论】:
标签: ios swift uidocumentinteraction