- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我创建了一个文件,我想通过 UIDocumentInteractionController
共享它。
我不确定如何从 documentsPath
和我保存文件的目标路径获取 URL
let someText = NSString(string: "Test")
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let destinationPath = documentsPath.stringByAppendingPathComponent("Data.txt")
var error:NSError?
let written = someText.writeToFile(destinationPath,
atomically: true,
encoding: NSUTF8StringEncoding,
error: &error)
if written{
println("Successfully stored the file at path \(destinationPath)")
let dic = UIDocumentInteractionController()
self.dic.URL = url
let v = sender as UIView
let ok = self.dic.presentOpenInMenuFromRect(
v.bounds, inView: v, animated: true)
最佳答案
修改你的代码如下
import UIKit
class ViewController: UIViewController {
var docController:UIDocumentInteractionController!
override func viewDidLoad() {
let someText = NSString(string: "Test")
if let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as? String {
let destinationPath = documentsPath.stringByAppendingPathComponent("Data.txt")
var error:NSError?
let written = someText.writeToFile(destinationPath,
atomically: true,
encoding: NSUTF8StringEncoding,
error: &error)
if written{
println("Successfully stored the file at path \(destinationPath)")
}
if let url = NSURL(fileURLWithPath: destinationPath) {
docController = UIDocumentInteractionController(URL: url)
}
}
}
@IBAction func sendFile(sender:AnyObject) {
docController.presentOptionsMenuFromRect(sender.frame, inView:self.view, animated:true)
}
}
现在将 IBAction 连接到 Storyboard中的按钮。下一页:
所以一切看起来像这样:
您现在可以构建并运行要测试的应用。
关于ios - UIDocumentInteractionController() swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29399341/
是否可以检查设备上有多少个能够处理特定文件类型的应用程序?基本上,我的应用程序中有一个按钮,允许用户在另一个应用程序中打开,但如果没有可能的应用程序可以打开文档,我不想显示它。 最佳答案 好吧,所以想
我不知道这段代码有什么问题,但每次运行应用程序时,显示菜单后,应用程序都会崩溃。 NSString * path = [[NSBundle mainBundle] pathForResource:@"
我在容器 View 中有一个 UIViewController。 View Controller 在 UIDocumentInteractionController 中显示 PDF,如下所示: let
我有一个 PDF 显示在 UIDocumentInteractionController它很棒。 问题是,该应用程序的重点是保护 PDF 不被共享等。因此我想摆脱出现的选项按钮。 堆栈上有 1000
我一直在使用 Apple 示例代码从这里查看文档: https://developer.apple.com/library/ios/samplecode/DocInteraction/Listings
我有从 UIAlertController 中调用的代码: func createSomeFile() { var output = (some NSData to output to fil
如何指定可用于 UIDocumentInteractionController 的“打开方式”功能的特定“白”应用程序列表?我在 UIDocumentInteractionController 文档中
我的应用程序中的一个屏幕显示了本地镜像的预览,我在左上角有一个操作按钮,我用它来显示文档交互选项: - (IBAction)actionButtonTapped:(id)sender { se
我有一个 ics(日历)文件,我使用 presentOptionsMenuFromRect: 使用 UIDocumentInteractionController 打开它。运行时,“打开方式”菜单看起
我的 IOS 应用程序的方向已锁定为纵向模式。但是,我想支持使用 UIDocumentInteractionController 打开的文件的横向和纵向。这是我打开文件 url 的代码。 let u
我使用 UIDocumentInteractionController 在我的应用程序中预览文档。但是,有时文档显示良好,有时交互 Controller 显示消息“读取文档时出错”。我知道这不是文档的
我对 UIDocumentInteractionController 非常绝望。我唯一想做的就是与注册 PDF 的所有其他应用程序共享我的应用程序中的 pdf 文件。 这是我的代码: NSString
这里有一个奇怪的 iOS 问题... 我有一个可以在我的 iPad 上打开 PDF 的应用程序。 (我只需要在我所处的环境中处理 iPad) 奇怪的是,有时当我尝试加载文件时(DocumentInte
我使用- (BOOL)presentPreviewAnimated:(BOOL)animated; 来加载文档,然后我想从文档中截取屏幕截图。所以我尝试 UIGraphicsBeginImageCon
在我的应用程序中,我下载各种格式的文件。我试图让 UIDocumentInteractionController 获得可以打开这种格式的应用程序。问题是 UIDocumentInteractionCo
我想在应用程序中分享保存的 PDF。实际上,它不适用于 PRINT,也不适用于 MAIL,它正在通过 Whatsapp 和其他应用程序进行共享。 { let fileManager = Fil
在我的 iOS 应用程序中,我使用 DocumentInteractionController 来预览 .csv 文档。 self.documentController = [UIDocume
在我的应用程序中,我想下载各种类型的文件并导出,以便用户可以使用打开此类文件的应用程序打开文件。我正在尝试使用 UIDocumentInteractionController 但在下载后将其保存到我的
我正在使用 UIDocumentInteractionController 与其他应用程序共享在我的应用程序中拍摄的图像。当您使用它与 Instagram 分享时,您可以使用包含键 @"Instagr
当用户从 tableView 中选择一个文件时,我试图从导航 Controller 中呈现一个 UIDocumentInteractionController。 interactionControll
我是一名优秀的程序员,十分优秀!