问题描述
如果我将文件保存在.app
捆绑包中,则可以保存,但苹果建议在应用程序支持中保存文件在
If i save files inside the .app
bundle, it saves OK, but apple recommends saving files inside the Application Supportunder
~/Library/Application Support/appname
或
~/Library/Application Support/bundleid
我都尝试过,但是我总是遇到异常.我正在获得应用程序支持的路径,即
I tried both, but I am always getting an exception. I am getting a path to the Application Support, which is
/Users/myname/Library/Application Support/com.company.appname/
或
/Users/myname/Library/Application Support/AppName/
在我的info.plist
中正确指定了
com.company.appname
,而AppName
是product AppName.app
,因此路径似乎正确.
com.company.appname
is specified correctly inside my info.plist
, and AppName
is product AppName.app
, so the paths seems correct.
{
FilepathProcessor::pathForFile(fpath, "menustate", ".sav",
PATH_TO_DESTINATION_SAVE_LOAD_FOLDER);
std::ofstream file;
file.exceptions(std::ofstream::eofbit | std::ofstream::failbit |
std::ofstream::badbit);
INFO_ARG("prepare to save to '%s'", fpath.c_str());
try {
file.open(fpath.c_str(), std::ios::out | std::ios::binary |
std::ios::trunc);
ERROR_IF_ARG(!file.is_open(), "couldnt open file for saving at '%s'",
fpath.c_str(), return);
//will pass this point
//exception happens by first write
WRITE_INT_TO_BINFILE(file, episode);
//...
}
catch (std::ofstream::failure e) {
ERROR_IF_ARG(true, "exception %s", e.what(), return);
}
file.close();
}
输出:
INFO : prepare to save to '/Users/myname/Library/Application
Support/com.comapny.appname/menustate.sav' [CALLED BY : saveToFile]
ERROR!
Text : exception basic_ios::clear
推荐答案
不是为您自动创建的目录不是.保存文件之前,首先需要检查目录是否存在,如果不存在,则需要创建目录.
The directory is not automatically created for you. Before saving the file, you first need to check if the directory exists, and if not, you need to create the directory.
这篇关于C ++ MAC OS X无法写入〜/Library/Application Support/< appname>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!