1

我想为 iPhone 实现锁屏调整。在锁屏上,我添加了一个可以解锁屏幕和打开手机应用程序的按钮。这个按钮动作的代码是:

[self unlockWithSound:YES];
int (*openApp)(CFStringRef, Boolean);
void* sbServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
openApp= (int(*)(CFStringRef, Boolean))dlsym(sbServices,"SBSLaunchApplicationWithIdentifier");
openApp(CFSTR("com.apple.mobilephone"), FALSE);
dlclose(sbServices);

但是当我点击此按钮执行此代码时,iOS 会在几秒钟内崩溃并重新启动。我的 iPhone 运行的是 iOS 6,经常越狱。

当我在后台线程中执行代码时,我在 syslog 文件中看到了这一点:

Entitlement com.apple.springboard.launchapplications required to use kern_return_t    _SBXXLaunchApplication(mach_port_t, char *, sbs_url_string_t, sbs_property_list_data_t, mach_msg_type_number_t, sbs_property_list_data_t, mach_msg_type_number_t, SBSApplicationLaunchFlags, SBSApplicationLaunchError *, audit_token_t)

在主线程中:

Oct 31 11:11:40 Kevin-Yes-iPhone lockdownd[41]: 2fe93000 _receive_message: walk away - non-SSL 1
Oct 31 11:12:13 Kevin-Yes-iPhone profiled[163]: (Note ) profiled: Idled. 
Oct 31 11:12:13 Kevin-Yes-iPhone profiled[163]: (Note ) profiled: Service stopping.
Oct 31 11:12:15 Kevin-Yes-iPhone securityd[363]: MS:Notice: Installing: (null) [securityd] (793.00)
Oct 31 11:12:15 Kevin-Yes-iPhone afcd[367]: Max open files: 125
Oct 31 11:12:17 Kevin-Yes-iPhone afcd[368]: Max open files: 125
Oct 31 11:12:33 Kevin-Yes-iPhone securityd[369]: MS:Notice: Installing: (null) [securityd] (793.00)
Oct 31 11:12:37 Kevin-Yes-iPhone lockdownd[41]: 2fe93000 _receive_message: walk away - non-SSL 1
Oct 31 11:13:00 Kevin-Yes-iPhone securityd[371]: MS:Notice: Installing: (null) [securityd] (793.00)

我的问题是:为什么我的调整不能执行这段代码?我使用 iosopendev 作为我的开发工具,是 iosopendev 的问题吗?

4

2 回答 2

2

这是解决我的问题的最佳方法:

%new(v@:@)
-(void)launch:(NSString *)bundle {
    Class SBApplicationController = objc_getClass("SBApplicationController");
    id appController = [SBApplicationController sharedInstance];

    NSArray *apps = [appController applicationsWithBundleIdentifier: bundle];
    if ([apps count] > 0) {
        //Wait .5 seconds.. then launch.
        [self performSelector:@selector(launchTheApp:) withObject:[apps objectAtIndex:0] afterDelay: 0.5];
    } else {
        id app = [appController applicationWithDisplayIdentifier: bundle];
        if (app) {
            //Wait .5 seconds.. then launch.
            [self performSelector:@selector(launchTheApp:) withObject:app afterDelay: 0.5];
        }
    }
}

%new(v@:@)
-(void)launchTheApp:(id)app {
    Class SBUIController = objc_getClass("SBUIController");
    id uiController = [SBUIController sharedInstance];
    if([uiController respondsToSelector:@selector(animateLaunchApplication:)]) {
        [uiController animateLaunchApplication:app animateDefaultImage:YES];
    } else {
        [uiController activateApplicationFromSwitcher:app];
    }
}

注意:activateApplicationFromSwitcher然后会更好activateApplicationAnimated

于 2013-10-31T10:01:53.477 回答
2

好的,我想我明白这里发生了什么。您正在编写在 SpringBoard 应用程序中运行的调整。通常,SBSLaunchApplicationWithIdentifier()可能(?)用于允许其他非 SpringBoard 代码通过 SpringBoardServices 打开应用程序。

SpringBoard调整的情况下,启动应用程序的更直接方法可能是遵循此处的文档......虽然我现在无法测试。 这是另一个基本上使用这种技术的 Stack Overflow 答案。

正如消息所暗示的那样,您尝试运行的代码确实需要com.apple.springboard.launchapplications权利。有趣的是,SpringBoard它本身并没有这种权利,可能是因为它只能直接启动应用程序。

于 2013-10-31T07:17:11.233 回答