如何在iOS中打开文件?

时间:2016-08-22 06:21:17

标签: ios swift

我尝试在下载后使用 Alamofire 下载.pdf文件。但我见过只使用过" webview"。因此,应用程序消耗大量内存并且不可行。

我想要的是使用本机设备应用程序打开它。有什么建议?谢谢。

编辑:这是我的下载文件代码:

    var localPath: NSURL?

    Alamofire.download(.GET, url, destination: { (temporaryURL, response) in
    let directoryURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
    let pathComponent = response.suggestedFilename
    localPath = directoryURL.URLByAppendingPathComponent(pathComponent!)
    return localPath!
    })
    .response { (request, response, _, error) in

    if error != nil
    {
    // got an error in getting the data, need to handle it
    print("Error: \(error!)")

    }

    //print(response)
    print("Download file en:\(localPath!)")

    self.view.hideToastActivity()
    //self.actioncall()

    }

 }

我需要从localpath打开文件......

1 个答案:

答案 0 :(得分:1)

您应该使用class Customer < ActiveRecord::Base self.table_name = "cust_tb" has_many :money has_many :gold end 。您可以在this Apple文档页面上阅读相关内容。

通过一些谷歌搜索你甚至可以看到一些示例实现。例如here您可以通过“ mattneub ”查看有关此操作的一些代码。

我再向您提供一个可以使用的代码:

UIDocumentInteractionController