Cydia应用程序文档文件夹未创建 [英] Cydia App Documents Folder Not Created

查看:133
本文介绍了Cydia应用程序文档文件夹未创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Core Data iOS应用程序,通过苹果的频道完美地工作 - iOS模拟器& Xcode安装,但是当我尝试手动安装到设备上时,应用程序崩溃。我的主要目标是将应用程式放在Cydia。



为Cydia准备应用程序的指南
我阅读了这篇文章,我在底部表示


Appstore应用程序具有由安装过程创建的文档文件夹。越狱应用程序不。它是由应用程序创建自己的文件夹。如果你需要这种类型的文件夹,你必须在你的applicationDidFinishLaunching函数中使用一个简单的mkdir命令来创建它。只需添加一个简单的函数:mkdir(/ var / mobile / Library / YOURAPPNAME,0755);如果文件夹已经存在,则不会造成危害。您想这样做,因为安装过程作为root用户运行,应用程序作为用户移动运行。


我不太了解Core Data的工作原理,但我知道Core Data数据库存储在Documents文件夹,我现在相信这是我的应用程序崩溃的原因。



mkdir函数在创建Documents文件夹时不起作用。



如何创建文档文件夹,以及如何让它与Core Data一起工作,确保数据库从我创建的文件夹加载?



提前感谢

$ b $很可能你仍然在创建和加载CoreData数据库文件的方法中使用AppStore友好的文档路径(我认为Xcode会把这些放在你的AppDelegate中)



检查加载 persistentStorageCoordinator 的方法,并查找如下所示的行:

  NSURL * storeUrl = [NSURL fileURLWithPath:[docPath stringByAppendingPathComponent:@my_cool_app.sqlite]]; 

并确保 docPath var / mobile / Library / My_Cool_App,而不是源自标准的AppStore友好:

  NSArray * documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask ,YES); 
NSString * docPath = [documentPaths objectAtIndex:0];

您可能想创建一个方法,根据编译应用程序的目标,返回正确的Documents目录for:

  +(NSString *)documentsDirectoryPath 
{
#ifdef JAILBREAK

NSString * documentPath = @/ var / mobile / Library / My_Cool_App;

if(![[NSFileManager defaultManager] fileExistsAtPath:documentPath])
{
[[NSFileManager defaultManager] createDirectoryAtPath:documentPath
withIntermediateDirectories:NO
:nil
error:NULL];
}

return documentPath;

#else

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

#endif
}


I have been working on a Core Data iOS app that works perfectly through Apple's "channels" – iOS simulator & Xcode installing, yet when I try to manually install it onto a device, the application crashes. My main goal is to put the app on Cydia.

A guide to preparing an app for Cydia I read this article, and I at the bottom it said

Appstore app has a Documents folder that is created by the installation process. Jailbroken app does not. It is up to the app to create its own folder. Should you need this type of folder, you must create this with a simple mkdir command in your applicationDidFinishLaunching function. Just add a simple function: mkdir("/var/mobile/Library/YOURAPPNAME", 0755); If the folder already exists, no harm done. You want to do this because the install process runs as user root and the app runs as user mobile. If Cydia does this for you then the folder will have the incorrect permissions.

I do not know much about how exactly Core Data works, but I know the Core Data "database" is stored in the Documents folder, and I now believe this is the cause of the crash of my app.

The mkdir function did not work in creating a Documents folder.

How would I go about creating a Documents folder, and how would I get it to work with Core Data, ensuring the database is loaded from this folder I created?

Thanks in advance

解决方案

Most likely you are still using the AppStore friendly Documents path in the methods which create and load the CoreData database file (I think Xcode will put these in your AppDelegate by default).

Check the method which loads the persistentStorageCoordinator and look for a line like this:

NSURL *storeUrl = [NSURL fileURLWithPath: [docPath stringByAppendingPathComponent:@"my_cool_app.sqlite"]];

And make sure that docPath is "/var/mobile/Library/My_Cool_App" and not originating from the standard AppStore friendly:

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [documentPaths objectAtIndex:0];

You might want to create a method which returns the proper Documents directory depending on what target you compile the app for:

+(NSString *)documentsDirectoryPath
{
#ifdef JAILBREAK

    NSString *documentPath = @"/var/mobile/Library/My_Cool_App";

    if (![[NSFileManager defaultManager] fileExistsAtPath:documentPath])
    {
        [[NSFileManager defaultManager] createDirectoryAtPath:documentPath
                              withIntermediateDirectories:NO 
                                               attributes:nil 
                                                    error:NULL];
    }

    return documentPath;

#else

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

#endif
}

这篇关于Cydia应用程序文档文件夹未创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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