iOS:使用C / C ++将文件写入Documents文件夹,并使用Files / iTunes或第三方工具轻松检索

我已经咨询了这个问题:

Writing to file in iOS using C/C++

及其答案:

https://stackoverflow.com/a/39022407/987846

我似乎已将文件写入磁盘,即所有文件的打开和写入均已完成。但是,当我希望看到写入磁盘的文件出现在iOS上的Files.app或macOS上的iTunes上时,我什么都没找到。特别是,我的应用程序没有出现在iTunes的“文件共享”类别中。

我还尝试了第三方工具,例如:

https://github.com/ios-control/ios-deploy

调用其文件下载命令会给我一个空文件夹

./ios-deploy --download=/Documents --bundle_id com.mycompany.myapp -2 dest_dir

那么关闭应用程序后我应该如何检索该文件?

greatmrr 回答:iOS:使用C / C ++将文件写入Documents文件夹,并使用Files / iTunes或第三方工具轻松检索

好的,自己弄清楚。

我需要通过在新行中输入新内容来向我的Info.plist添加目标属性:

UIFileSharingEnabled

或只是从属性列表中选择

Application supports iTunes file sharing

设置值为YES。 然后,我的应用程序将显示在iTunes File Sharing类别中。 保存到“文档”文件夹中的文件将出现在此处。

为完整起见,下面是可插入基于ObjC的项目中的ObjC / C代码段。


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *file = [documentsDirectory stringByAppendingPathComponent:@"file.ext"];
    const char* filePath = [file UTF8String];
    FILE* pFile = NULL;
    pFile = fopen(filePath,"ab");
    float data = 9.9f;
    fwrite(&data,sizeof(float),1,pFile);    
    fclose(pFile);
}
本文链接:https://www.f2er.com/3039230.html

大家都在问