我已经为我的应用程序创建了一个包含数据的 sqlite 数据库,并将其拖到 Xcode 中的支持文件组中。
当我尝试使用以下方式访问它时:
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.db"];
它不读取文件。但是,如果我输入完整的文件路径:
NSString *bundlePath = @"Users/xxxx/Apps/App/database.db";
该应用运行良好。
我打印出的文件路径来自:
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.db"];
它是:
/Users/xxx/Library/Application Support/iPhone Simulator/5.1/Applications/EE614EFA-BAF9-478E-xxxx-xxxx/App.app/database.db
有什么想法吗?
最佳答案
处理路径的最佳方式是让 API 处理有关将内容“附加”到路径字符串的细节。
NSString *path = [[NSBundle mainBundle] pathForResource:@"database"
ofType:@"db"];
关于iphone - resourcePath 不工作 Xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11447010/