Launch other application without URL schema in iphone?

一世执手 提交于 2019-11-27 13:23:23
Kevin Lee

I used this way:

void* sbServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
int (*SBSLaunchApplicationWithIdentifier)(CFStringRef identifier, Boolean suspended) = dlsym(sbServices, "SBSLaunchApplicationWithIdentifier");
int result = SBSLaunchApplicationWithIdentifier((CFStringRef)bundleId, false);
dlclose(sbServices);

And you need entitlements granted to your app:

 <key>com.apple.springboard.launchapplications</key>
 <true/>

It can run on iOS 6.

There are several ways you can launch an app using the Bundle ID.

SBApplication

SBApplication *app = [[objc_getClass("SBApplicationController") sharedInstance] applicationWithDisplayIdentifier:@"com.wrightscs.someapp"];
[[objc_getClass("SBUIController") sharedInstance] activateApplicationFromSwitcher: app];

SBApplicationController

SBUIController *uicontroller = (SBUIController *)[%c(SBUIController) sharedInstance];
SBApplicationController *appcontroller = (SBApplicationController *)[%c(SBApplicationController) sharedInstance];

if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{
    [uicontroller activateApplicationFromSwitcher:[[appcontroller applicationsWithBundleIdentifier:bundleID] objectAtIndex:0]];
}
else
{
    // doesn't work outside of Springboard
    [uicontroller activateApplicationAnimated:[[appcontroller applicationsWithBundleIdentifier:bundleID] objectAtIndex:0]];
}

There was another method I used in 4.x and SBUIController but that stopped working in 5.0 so I'm not going to post it.

As I know, only private api can do this. First

@interface PrivateApi_LSApplicationWorkspace
- (bool)openApplicationWithBundleID:(id)arg1;
@end

then use it

PrivateApi_LSApplicationWorkspace* _workspace;
_workspace = [NSClassFromString(@"LSApplicationWorkspace") new];
[_workspace openApplicationWithBundleID:bundleIdentifier];

You can check https://github.com/wujianguo/iOSAppsInfo.

I have tested just now: working in iOS 9.3.5 & 11.2 and also this method do not require any includes or dynamics loading of libs. Relies fully on obj-c runtime. And also this method do not require jailbroken device, can be done with xcode device and free developer account with provisioning profiles. Don't think that it would pass App store review process, but can be succesfully used in enterprise or ad-hoc destribution and so on.

id wrkS;
wrkS = [NSClassFromString(@"LSApplicationWorkspace")  performSelector:@selector(defaultWorkspace)];
[wrkS performSelector:@selector(openApplicationWithBundleID:) withObject:@"com.apple.reminders"];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!