Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

objective c - Special API to launch an app from my application

I had asked a question here but the answer guide me to open a new topic. Shortly, i want to launch a free app on Appstore from my application but the app i want to launch has no URL Scheme. The comments on my other question say using some special APIs like SBSLaunchApplicationWithIdentifier or classes like UIDocumentInteractionController make it possible. Can anyone please help me how to launch an application from my appication. Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Let me first say that this method is jailbreak only! It uses private API's that Apple can stop supporting at any time in a future version!

Let's get to it, this method uses the [UIApplication launchApplicationWithIdentifier:suspended:] private method:

[[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.Preferences" suspended:NO];

From what I've tested calling this method from an application not running as root is useless, apparently SpringBoard (or LaunchServices) only allow root applications to launch other applications using this method.

So, first you need to jailbreak your iPhone, then you need to get your application running as root.

To get your app running as root you need to place it in /Applications/YourApp.app instead of the usual /User/Applications/UUID/YourApp.app.

You can install OpenSSH using Cydia and use SSH to access your phone's shell.

Then, after having your app in the right place you need to set permissions, for example:

enter image description here

I would use the same ones as Cydia:

chown -R root:wheel /Applications/YourApp.app

Next, a little trick. The binary will need the setuid bit:

chmod 4755 /Applications/YourApp.app/YourApp

And for the last step, SpringBoard doesn't open apps with the setuid bit, but it opens a script (which can open another app)! Just change the name of the binary to something like YourApp_:

mv /Applications/YourApp.app/YourApp /Applications/YourApp.app/YourApp_

And create a new file named YourApp in your app folder with the following script:

#!/bin/bash
CrrDir=$(dirname "$0")
exec "${CrrDir}"/YourApp_

Now, just respring (there's an app for that in Cydia) and you're ready to go.

Sorry if this seems hard, it isn't, I don't remember where I learned it, but it was a long time ago. This method works fine in all iOS versions and I've just tested it with iOS 5.1.

Again, YOUR APP WILL NOT BE APPROVED BY APPLE IF YOU DO THIS.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...