objective-c - 如何制作目录iOS?

标签 objective-c cydia

好的,

所以我有一个 Cydia 应用程序需要更新。我知道 Cydia 应用程序没有文档文件夹,因此您必须创建一个。以下是我之前在 iOS 4 中的做法(在 iOS 5 上不起作用):

mkdir("/var/mobile/Library/APPNAME", 0755);
mkdir("/var/mobile/Library/APPNAME/Documents", 0755);

NSString *foofile = @"/var/mobile/Library/APPNAME/Documents/database.db";
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];

if (fileExists == TRUE) {
    NSLog(@"already exists");
} else {
    NSLog(@"doesn't exists");
    NSFileManager *fileManager = [[NSFileManager defaultManager]autorelease];
    NSError *error;
    NSString *documentDBFolderPath = @"/var/mobile/Library/APPNAME/Documents/database.db";

    NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.db"];
    [fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath error:&error];

}

我还包含了将数据库文件复制到该文件夹​​的代码。这不起作用(即使我通过 SSH 手动创建文件夹)。

求助!谢谢。

最佳答案

下面是我创建目录的方法

-(void)createDirectory:(NSString *)directoryName atFilePath:(NSString *)filePath
{
    NSString *filePathAndDirectory = [filePath stringByAppendingPathComponent:directoryName];
    NSError *error;

    if (![[NSFileManager defaultManager] createDirectoryAtPath:filePathAndDirectory
                                   withIntermediateDirectories:NO
                                                    attributes:nil
                                                         error:&error])
    {
        NSLog(@"Create directory error: %@", error);
    }
}

关于objective-c - 如何制作目录iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8030054/

相关文章:

compiler-errors - 编译cydia时出现错误1

ios - Cydia 包 preinst/postinst 无法重新加载启动守护进程

ios - 格式化体积和质量单位

ios - 超过 256 个顶点的 OpenGL ES2 网格断开

objective-c - 这个复制类方法会泄漏内存吗?

iphone - 来自 Cydia 的应用程序的 Settings.bundle 和钥匙串(keychain)不起作用

iphone - 使用 Apple 代码签名为 Cydia 构建应用程序

iOS,在 Objective C 中使用结构,结构值不可从 super View 分配

iOS 7/8 Objective C - 将混合模式应用于 View

ios - IOKit ARM7* 二进制文件,它位于 iPhone 设备上的什么位置?