ios*_*eak 29 objective-c cydia
好的,
所以我有一个我需要更新的Cydia应用程序.我知道Cydia应用程序他们没有Documents文件夹,所以你必须制作一个.以下是我之前在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];
}
Run Code Online (Sandbox Code Playgroud)
我还包括将数据库文件复制到该文件夹的代码.这不起作用(即使我通过SSH手动创建文件夹).
请帮忙!谢谢.
syc*_*efx 62
这是我创建目录的方法
-(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);
}
}
Run Code Online (Sandbox Code Playgroud)
尝试使用createDirectoryAtURL:withIntermediateDirectories:attributes:error:.
createDirectoryAtURL:withIntermediateDirectories:attributes:error:在指定路径创建具有给定属性的目录.
参数
url- 指定要创建的目录的文件URL.如果要指定相对路径,则必须在创建相应的NSURL对象之前设置当前工作目录.此参数不得为零.
createIntermediates- 如果YES,此方法创建任何不存在的父目录作为在url中创建目录的一部分.如果NO,如果任何中间父目录不存在,此方法将失败.如果任何中间路径元素对应于文件而不是目录,则此方法也会失败.
attributes- 新目录和任何新创建的中间目录的文件属性.您可以设置所有者和组编号,文件权限和修改日期.如果为此参数指定nil或省略特定值,则使用一个或多个默认值,如讨论中所述.有关可以包含在此字典中的键列表,请参阅"常量"(第54页)一节,其中列出了在属性字典中用作键的全局常量.某些键(如NSFileHFSCreatorCode和NSFileHFSTypeCode)不适用于目录.
error- 输入时,指向错误对象的指针.如果发生错误,则将此指针设置为包含错误信息的实际错误对象.如果您不想要错误信息,可以为此参数指定nil.
YES如果目录已创建或已存在,则返回值; 如果发生错误,则返回NO.