iOS调用文件app(file.app)选择文件和下载

第三方应用调用系统文件app,并下载文件。

###配置如下
1:证书文件配置
在Identifiers下创建你的iCloud Containers配置,点击“+”创建

2:在Identifiers下选择你要添加icloud的boundid把icloud配置勾选上既可

3:打开工程中的配置如下
工程配置icloud.jpg

4:可选配置
在info.plist中添加如下两个配置
Supports opening documents in place
Application supports iTunes file sharing
结果都为YES
设置完以后,会在文件app中有一个和你工程名相同的文件夹出现。

5:打开文件app

- (void)presentDocumentCloud {
   
    NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code ", @"public.image", @"public.audiovisual-content", @"com.adobe.pdf", @"com.apple.keynote.key", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt"];
    
    UIDocumentPickerViewController *documentPickerViewController =
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码的问题在于,它在每次写入日志时都会打开和关闭文件。这种操作会导致不必要的文件I/O开销,影响性能,并且可能会导致文件锁定和竞争问题。在高并发的情况下,这可能会导致程序崩溃或数据丢失。 为了解决这个问题,可以将文件打开的操作移动到构造函数中,这样只需要在对象创建时打开一次文件,然后在析构函数中关闭文件。同时,可以添加一个缓冲区,以便在缓存中收集足够的数据后,再一次性地将其写入文件。这可以通过使用`std::endl`或`std::flush`来实现。 例如,修改后的代码可能如下所示: ``` class MyLog { public: MyLog(const std::string& logFilePath); ~MyLog(); void toLogA(const std::string& str); private: std::ofstream file; std::string logFilePath; std::stringstream buffer; }; MyLog::MyLog(const std::string& logFilePath) { this->logFilePath = logFilePath; this->file.open(logFilePath.c_str(), std::ios::app); } MyLog::~MyLog() { if (this->file.is_open()) this->file.close(); } void MyLog::toLogA(const std::string& str) { buffer << str << "\n"; if (buffer.str().length() > 1024) { // 缓冲区大小达到1024时写入文件 file << buffer.str(); file.flush(); buffer.str(""); } } ``` 这样,每次调用`toLogA()`方法时,日志信息都会被写入缓冲区中。当缓冲区大小达到1024时,缓冲区中的内容会被写入文件,并清空缓冲区。在对象销毁时,文件会被自动关闭。这种方法可以避免频繁的文件I/O操作,提高性能,同时减少文件锁定和竞争问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值