除了使用Objective-C之外,还有其他方法可以在iOS中获取文件路径吗? [英] Is there a way to get a file path in iOS other than with Objective-C?

查看:154
本文介绍了除了使用Objective-C之外,还有其他方法可以在iOS中获取文件路径吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone制作游戏,我的游戏对象是C ++,我保存并加载了该类中的用户数据.我正在使用文本文件以及std :: ifstream和std :: ofstream进行读写.在开发过程中,我只是将文本文件从我的Supporting Files文件夹中拖动到代码中的两个"之间,因此我得到了一条用于测试的路径.现在,我想完成该代码,以便它可以在用户的​​设备上运行.

有没有一种方法可以使用Objective-C获取或硬编码文件路径 ,如

I''m making a game for iPhone and my game object is in C++ and I save and load user data from that class. I am using a text file and std::ifstream and std::ofstream for reading and writing. During development I''ve just been dragging the text file from my Supporting Files folder to between the two "" in my code and I get a path which has worked for testing. Now I''d like to finalize that code so that it will work on users'' devices.

Is there a way I can get, or hard-code a file path without using Objective-C, as in

NSString * filePath = [[NSBundle mainBundle] pathForResource:@"UserData"
                                                      ofType:@"txt"];


如果没有,那么工程师获得文件路径的好方法是什么?我可以在不使用C ++类中使用Objective-C的情况下做到这一点吗?问题实际上是关于可移植性的编码样式和设计,因为该游戏将被移植到Android设备上.

我在阅读一些有关沙盒的知识.我应该努力保护我的文件,还是没有文件我可以逃脱吗?



我已经想到了这一点,在Objective-C视图中创建一个获取路径并从C ++类调用它的函数,但是然后我必须在C ++类中有一个指向Objective-C类的指针.

或者,在事情开始时让Objective-C类调用c ++类的setter函数.

我只是做不到足够的事情来了解好的样式.


If not, what would be a good way to engineer getting the file path? Can I do it in a way without using Objective-C in my C++ class? The question is really about coding style and design for portability, since the game will be ported to Android devices.

I was reading a little bit about sand-boxing. Should I make efforts to safeguard my file or can I get away without it?



I''ve thought of this, creating a function in the Objective-C view that gets the path and calling that from the C++ class, but then I''d have to have a pointer to the Objective-C class in the C++ class.

Or, have the Objective-C class call a setter function of the c++ class when things start up.

I just haven''t done enough of this to know good style.

推荐答案

您应该是一个好公民,并使用苹果方式在设备上保存文件.这也将有助于进行备份或在iCloud中移动.

NSArray *路径= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);

一些好的材料=> http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS [
you should be a good citizen and use the apple way for files on the device. That will also help to make backups or move in the iCloud.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

some fine material => http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS[^]


PS: here is more Windows stuff, at stackoverflow is obj-c ;-)


这篇关于除了使用Objective-C之外,还有其他方法可以在iOS中获取文件路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆