是否可以将新文件写入iOS应用程序中的捆绑资源目录?

是否可以将新文件写入iOS应用程序中的捆绑资源目录?,ios,resources,bundle,Ios,Resources,Bundle,是否可以将新文件写入iOS应用程序中的捆绑资源目录?否无法写入捆绑目录。。因为bundle dir是用SSL证书进行代码签名的,您不能破坏它。但是,您可以轻松地在iphone应用程序的documents目录中编写 您可以使用以下命令获取文档目录路径- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); return [paths objectAtIndex

是否可以将新文件写入iOS应用程序中的捆绑资源目录?

否无法写入捆绑目录。。因为bundle dir是用SSL证书进行代码签名的,您不能破坏它。但是,您可以轻松地在iphone应用程序的documents目录中编写

您可以使用以下命令获取文档目录路径-

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
return [paths objectAtIndex:0];

或者,您可以复制所需的资源,然后在具有写入权限的情况下对文件进行操作

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

NSString *documentsDir = dirPaths[0];

NSString *databasePath = [documentsDir stringByAppendingString:@"/TwigitDatabase.db"];

NSFileManager *fm = [NSFileManager defaultManager];

if(![fm fileExistsAtPath:databasePath]) {   // Checking whether the my database was copied earlier, though it could be saved in some preferences property.
    NSError *error;
        NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"TwigitDatabase" ofType:@"db"];
    [[NSFileManager defaultManager] copyItemAtPath:soundFilePath toPath:databasePath error:&error];

    NSLog(@"%@", error);


}