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

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

问题描述

我一直在开发一个 Core Data iOS 应用程序,它可以通过 Apple 的渠道"完美运行——iOS 模拟器 &Xcode 正在安装,但是当我尝试将其手动安装到设备上时,应用程序崩溃了.我的主要目标是将该应用放在 Cydia 上.

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.

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

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

Appstore 应用有一个安装过程创建的 Documents 文件夹.越狱应用程序没有.由应用程序创建自己的文件夹.如果您需要这种类型的文件夹,您必须在 applicationDidFinishLaunching 函数中使用简单的 mkdir 命令创建它.只需添加一个简单的函数: mkdir(/var/mobile/Library/YOURAPPNAME", 0755);如果该文件夹已经存在,则不会造成任何伤害.您想这样做是因为安装过程以 root 用户身份运行,而应用程序以用户 mobile 身份运行.如果 Cydia 为您执行此操作,则该文件夹的权限将不正确.

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.

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

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.

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

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

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

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?

提前致谢

推荐答案

很可能您仍在创建和加载 CoreData 数据库文件的方法中使用 AppStore 友好的 Documents 路径(我认为 Xcode 会将这些放在您的 AppDelegate 中)默认).

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).

检查加载 persistentStorageCoordinator 的方法并查找如下一行:

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

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

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

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];

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

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天全站免登陆