您的位置:首页 > 移动开发

判断有没有越狱,以及读系统info.plist

2012-05-09 12:32 369 查看
1。判断是否越狱

detectDevice.h

@interface UIDevice (Helper)

- (BOOL)isJailbroken;

@end

detectDevice.m

@implementation UIDevice (Helper)

- (BOOL)isJailbroken {

BOOL jailbroken = NO;

NSString *cydiaPath = @“/Applications/Cydia.app”;

NSString *aptPath = @“/private/var/lib/apt/”;

if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath]) {

jailbroken = YES;

}

if ([[NSFileManager defaultManager] fileExistsAtPath:aptPath]) {

jailbroken = YES;

}

return jailbroken;

}

@end

然后在你代码中调用[UIDevice currentDevice] isJailbroken], 如果返回YES说明被破解了,为NO,则没被破解

2。越狱的机可以去获取已安装的程序

NSFileManager* fileManager = [NSFileManager defaultManager];
NSMutableArray* applist = [NSMutableArray arrayWithCapacity:10];
for (NSString *path in [fileManager directoryContentsAtPath:@"/var/mobile/Applications"]) {
for (NSString *subpath in [fileManager directoryContentsAtPath:
[NSString stringWithFormat:@"/var/mobile/Applications/%@", path]]) {
if ([subpath hasSuffix:@".app"])
{
NSString* infoplist =  [NSString stringWithFormat:@"/var/mobile/Applications/%@/%@/Info.plist", path, subpath];
NSLog(@"sdfsadfa0%@",infoplist);
NSDictionary* dict =  [NSDictionary dictionaryWithContentsOfFile:infoplist];
NSLog(@"sdfsadfa1%@",dict);

[applist addObject:[dict objectForKey:@"CFBundleDisplayName"]];
}
}


3。如果没有越狱的机

openURL能帮助你运行Maps,SMS,Browser,Phone甚至其他的应用程序。

openURL的使用方法:

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:myURLString]];

自己定义URL,方法如下:

打开info.plist,添加一项URL types

展开URL types,再展开Item1,将Item1下的URL identifier修改为URL Scheme

展开URL Scheme,将Item1的内容修改为myapp

或者:

(增加一下此段设置)

<key>CFBundleURLTypes</key>

<array>

<dict>

<key>CFBundleURLSchemes</key>

<array>

<string>myapp</string>

</array>

<key>CFBundleURLName</key>

<string>com.yourcompany.appName</string>

</dict>

</array>

其他程序可通过myapp://访问此自定义URL

可通过[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"myapp://com.yourcompany.appName"]];

来判断用户机器中是否安装了该程序

最近接触到程序内打开自己,通过第三方控件来调用本身程序:

通过- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

可以通过处理url来获取信息扫行相应操作。

4,获取ios进程的程序

// .h

@interface UIDevice (ProcessesAdditions)
- (NSArray *)runningProcesses;
@end

// .m
#import <sys/sysctl.h>

@implementation UIDevice (ProcessesAdditions)

- (NSArray *)runningProcesses {

int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
size_t miblen = 4;

size_t size;
int st = sysctl(mib, miblen, NULL, &size, NULL, 0);

struct kinfo_proc * process = NULL;
struct kinfo_proc * newprocess = NULL;

do {

size += size / 10;
newprocess = realloc(process, size);

if (!newprocess){

if (process){
free(process);
}

return nil;
}

process = newprocess;
st = sysctl(mib, miblen, process, &size, NULL, 0);

} while (st == -1 && errno == ENOMEM);

if (st == 0){

if (size % sizeof(struct kinfo_proc) == 0){
int nprocess = size / sizeof(struct kinfo_proc);

if (nprocess){

NSMutableArray * array = [[NSMutableArray alloc] init];

for (int i = nprocess - 1; i >= 0; i--){

NSString * processID = [[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid];
NSString * processName = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm];

NSDictionary * dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName, nil]
forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName", nil]];
[processID release];
[processName release];
[array addObject:dict];
[dict release];
}

free(process);
return [array autorelease];
}
}
}

return nil;
}

@end

// Example usage.
NSArray * processes = [[UIDevice currentDevice] runningProcesses];
for (NSDictionary * dict in processes){
NSLog(@"%@ - %@", [dict objectForKey:@"ProcessID"], [dict objectForKey:@"ProcessName"]);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息