使用公共API进行iphone越狱开发
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ABAddressBook
和NSFileManager
都有一个返回唯一的共享对象的类方法 - 在上面的代码中,对[NSFileManager defaultManager]
的调用会检索根据文档,“文件系统的默认NSFileManager
对象”。当您从命令行运行应用程序时,您可能没有执行初始化共享对象的部分或全部代码;你甚至可能从类方法中返回nil
。如果是这样,您可以通过创建自己的对象(即使用
[[NSFileManager alloc] init]
或[ABAddressBook addressBook]
)来解决此问题而不是依赖类方法返回共享对象。Both
ABAddressBook
andNSFileManager
have a class method that returns a unique, shared object – in your code above, the call to[NSFileManager defaultManager]
retrieves "the defaultNSFileManager
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 backnil
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.