gpt4 book ai didi

ios - 如何在 iOS 中保存公共(public) .txt 文件(这样任何文本阅读器应用程序都可以打开它)

转载 作者:行者123 更新时间:2023-11-29 02:25:02 35 4
gpt4 key购买 nike

我知道如何创建文本文件,但它只能在我的应用程序中访问。

我需要添加什么才能使这是任何 iOS 文件浏览器都可以找到并打开的公共(public)文档?

func saveInstructions(sender:AnyObject)
{
var savePath = fileDir()
var fileName = "filters.text"
var fileAtPath = savePath.path?.stringByAppendingPathComponent(fileName)
if(NSFileManager.defaultManager().fileExistsAtPath(fileAtPath!) == false)
{
NSFileManager.defaultManager().createFileAtPath(fileAtPath!, contents: nil, attributes: nil)
}
var fileHandle:NSFileHandle = NSFileHandle(forWritingAtPath: fileAtPath!)!
fileHandle.seekToEndOfFile()
fileHandle.writeData("text".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!)

}

最佳答案

因为 iOS 使用 App Sandboxing ,其他应用程序无法访问您应用程序中的文件(您也无法访问它们应用程序中的文件)。

使文件可供其他应用程序使用的唯一方法是使用 UIActivityViewController。这使您可以将文件导出到其他应用程序。但是,他们的应用程序中的文件与您的文件是分开的,在一个应用程序中所做的任何更改都不会影响另一个应用程序中的副本。

UIActivityViewController 的文档是 here并找到了一篇关于该主题的精彩 NSHipster 文章 here .

关于ios - 如何在 iOS 中保存公共(public) .txt 文件(这样任何文本阅读器应用程序都可以打开它),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27662735/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com