I want to implement a lockscreen tweak for the iPhone. On the lockscreen, I added a button which can unlock the screen and open the phone app. The code of this button action is:
[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);
But when I tap this button to execute this code, iOS crashes and reboots in several seconds. My iPhone is running iOS 6, regularly jailbroken.
I saw this in the syslog file when I executed the code in background thread:
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)
and in main thread:
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)
My question is: why can't my tweak execute this code? I am using iosopendev as my developing tool, is it a problem with iosopendev?
Here is the best way to solve my problem:
%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];
}
}
Note: activateApplicationFromSwitcher
will work better then activateApplicationAnimated