IOS 真机 FileUtils::getInstance()->getWritablePath() 返回空值

环境: cocos2dx 3.11, ios系统9.5.3,机型iphone4s

因为使用sqlite3数据库,真机上需要将数据文件拷贝到可写文件夹下进行操作,使用下面这个方法取路径的时候,destPath一直得到的是空值。

std::string destPath = FileUtils::getInstance()->getWritablePath();

但是奇怪的是,我在apple实现文件CCFileUtils-apple.mm 这个函数上设上断点,跑进来以后,strRet是拿到了可写文件路径的,但是return出去以后,外面的destPath拿不到,一直是空。

std::string FileUtilsApple::getWritablePath() const
{
if (_writablePath.length())
{
return _writablePath;
}

// save to document folder
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
std::string strRet = [documentsDirectory UTF8String];
strRet.append("/");
return strRet;

}

这个问题怎么破。。。。。求解

std::string destPath = FileUtils::getInstance()->getWritablePath(); 不能放在static函数中使用,不然得不到值,移到类函数中就能得到值。

1赞