使用公共API进行iphone越狱开发

发布于 2024-12-21 07:53:32 字数 1373 浏览 2 评论 0原文

我有一个使用 ABAdressBook API 的应用程序NSFileManager

当我从命令行运行应用程序时 - API 似乎无法检索 AddressBook/NSFileManager 信息 - 但是当我从跳板运行它时 - 它确实显示了所需的信息。

是因为我的应用程序从命令行运行时没有 UI 吗?

int main(int argc, char *argv[]) 
{
    @autoreleasepool 
    {
        printf("HELLO TEST\n");       
        NSLog(@"---------");
        NSMutableArray* dbList = [[NSMutableArray alloc] init];

        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSLog(@"file manager address is %@",fileManager);
        NSDirectoryEnumerator *dirnum = [fileManager enumeratorAtPath: @"/private/"];
        NSLog(@"dirNum is %@",dirnum);
        NSString *nextItem = [NSString string];

        while( (nextItem = [dirnum nextObject])) {
            if ([[nextItem pathExtension] isEqualToString: @"db"] ||
                [[nextItem pathExtension] isEqualToString: @"sqlitedb"]) {
                if ([fileManager isReadableFileAtPath:nextItem]) {
                    [dbList addObject:nextItem];

                    NSLog(@"%@", nextItem);
                }
            }
        }
    }
}

编辑:我将问题归结为以下选择器: [文件管理器 isReadableFileAtPath:nextItem] 当我从 SpringBoard 运行此函数时 - 它返回 true - 对于几个文件...

当我在命令行中运行它时 - 它对所有文件返回 false - 尽管我正在以 root 权限运行应用程序。

知道什么会导致这种行为改变吗?

谢谢, 伊泰

I have an app that is using the ABAdressBook API & NSFileManager.

When i'm running the application from the command line - the API doesn't seems to retrieve
the AddressBook/NSFileManager information - but when i run it from the springboard - it does show me the information required.

Is it because my app doesn't have a UI when it run from the command line?

int main(int argc, char *argv[]) 
{
    @autoreleasepool 
    {
        printf("HELLO TEST\n");       
        NSLog(@"---------");
        NSMutableArray* dbList = [[NSMutableArray alloc] init];

        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSLog(@"file manager address is %@",fileManager);
        NSDirectoryEnumerator *dirnum = [fileManager enumeratorAtPath: @"/private/"];
        NSLog(@"dirNum is %@",dirnum);
        NSString *nextItem = [NSString string];

        while( (nextItem = [dirnum nextObject])) {
            if ([[nextItem pathExtension] isEqualToString: @"db"] ||
                [[nextItem pathExtension] isEqualToString: @"sqlitedb"]) {
                if ([fileManager isReadableFileAtPath:nextItem]) {
                    [dbList addObject:nextItem];

                    NSLog(@"%@", nextItem);
                }
            }
        }
    }
}

Edit: I pinned the issue down to the following selector:
[fileManager isReadableFileAtPath:nextItem]
when i run this function from the SpringBoard - it returns true - for several of the files...

when i run it in the command line - it return false to all of the files - although i'm running the app with root privileges.

any idea what can cause this change in behavior?

Thanks,
Itay

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹏雨一样淡蓝的深情 2024-12-28 07:53:32

ABAddressBookNSFileManager 都有一个返回唯一的共享对象的类方法 - 在上面的代码中,对 [NSFileManager defaultManager] 的调用会检索根据文档,“文件系统的默认 NSFileManager 对象”。当您从命令行运行应用程序时,您可能没有执行初始化共享对象的部分或全部代码;你甚至可能从类方法中返回nil

如果是这样,您可以通过创建自己的对象(即使用 [[NSFileManager alloc] init][ABAddressBook addressBook])来解决此问题而不是依赖类方法返回共享对象。

Both ABAddressBook and NSFileManager have a class method that returns a unique, shared object – in your code above, the call to [NSFileManager defaultManager] retrieves "the default NSFileManager object for the file system", according to the docs. When you run your app from the command line, you're probably not executing some or all of the code that initializes the shared object; you may even be getting back nil from the class method.

If so, you may be able to work around this problem by creating your own object (that is, by using [[NSFileManager alloc] init] or [ABAddressBook addressBook]) rather than relying on the class method to return a shared object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文