简体   繁体   English

Cocos2d-x UserDefault 数据在 IOS 中的路径/位置?

[英]Path / Location of Cocos2d-x UserDefault data in IOS?

I am tasked to migrate an IOS game made with Cocos2d-x into Unity.我的任务是将使用 Cocos2d-x 制作的 IOS 游戏迁移到 Unity。 One of the issues I have is that I don't know where Cocos2d-x writes the user's saved data.我遇到的问题之一是我不知道 Cocos2d-x 将用户保存的数据写入哪里。 The Unity version of the app needs to access that data so that the user doesn't lose their progress.应用程序的 Unity 版本需要访问该数据,以便用户不会丢失他们的进度。

The Cocos2d-x application saves it's data using something like this: userDefault->setIntegerForKey("coins", 35); Cocos2d-x 应用程序使用如下方式保存数据: userDefault->setIntegerForKey("coins", 35);

Would anybody know what path/location that user's saved data is stored?有人知道用户保存的数据存储在什么路径/位置吗? Are there ways I can find that out?有什么办法可以找出来吗? I've already tried to view it on xcode via Window > Devices and Simulators > Installed Apps but the app isn't listed.我已经尝试通过Window > Devices and Simulators > Installed Apps在 xcode 上查看它,但未列出该应用程序。

Any help would be appreciated.任何帮助,将不胜感激。 Thanks.谢谢。

In cocos2d-x v4:在 cocos2d-x v4 中:

// write string
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithUTF8String:value.c_str()] forKey:[NSString stringWithUTF8String:pKey]];

// read string
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithUTF8String:pKey]];

// read integer
NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithUTF8String:pKey]];

Before V 2.1.2 the info was stored in UserDefault.xml在 V 2.1.2 之前,信息存储在 UserDefault.xml

#define XML_FILE_NAME "UserDefault.xml"

#ifdef KEEP_COMPATABILITY
    if (! _isFilePathInitialized)
    {
        // xml file is stored in cache directory before 2.1.2
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        _filePath = [documentsDirectory UTF8String];
        _filePath.append("/");

       _filePath +=  XML_FILE_NAME;
      _isFilePathInitialized = true;
    }
#endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM