views:

218

answers:

5

hello,

I am writing an application in Objective-C whose functionality is to call and execute another application.Pls can i know the procedure???Let me also know where i need to keep the calling application which has to load and execute???

A: 

I'm not sure I fully understand your question, but if all you're trying to do is launch another app, there are a number of ways to do this. The most straightforward is probably by using the NSTask class. Here is a simple example of launching iCal from within an Objective-C application using an NSTask.

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/Applications/iCal.app/Contents/MacOS/iCal"];
[task launch];
[task release];
Gene Goykhman
Hi thanks for the answer.Now i have referred to NSTask but it is only in Mac OS but the program which i do is with iPhone OS and it does not have NSTask class.Can you please tell me which is the equivalent for iPhone OS?????
suse
Hi Gene pls do suggest me????
suse
**NEVER** do this example in shipping code. NSTask is intended for launching non-GUI applications. For launching GUI apps, use NSWorkspace or the lower-level Launch Services.
Mike Abdullah
A: 

See the -launchApplication: method of the NSWorkspace class.

NSResponder
I'm fairly certain that the iPhone SDK also does not have NSWorkspace.
Williham Totland
launchApplication: is not available on the iPhone, sandbox and all.
duncanwilcox
Can u please suggest me what will be the equivalent function of launchAppliation in iPhone-OS?????
suse
Oops, didn't spot that it was a cocoa-touch question, not a cocoa question.
NSResponder
A: 

It is worth noting at this point that you are unlikely to be able to launch another application on the iPhone; the best you can do is probably detaching to another app; and even that might be nontrivial. (On the iPhone, 3rd party/userland applications cannot live in the background.)

Williham Totland
+3  A: 

The only way to "launch" another application is if the other application "cooperates" with yours, if you will.

The cooperation comes in the form of a URL protocol scheme that an application exposes. Examples are mailto: (exposed by the system mail application) and sms: (exposed by the Messages app).

http://wiki.akosma.com/IPhone%5FURL%5FSchemes seems to have a comprehensive list of third party apps exposing a custom protocol scheme that you can make use of.

Launching another app is a matter of calling [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitterrific://..."]; (for example).

As of OS 3.0 you can also check if a given URL protocol scheme is available via UIApplication's -canOpenURL: — checking if some app has registered the protocol scheme, or in other words checking if an application is installed.

If you are writing both apps yourself then launching a custom protocol scheme is pretty simple, however you can't launch an arbitrary iPhone app, and you wouldn't be able to enumerate available apps anyway because of the sandbox.

duncanwilcox
Hi i actually want to call a small application(ex: Hello World ) from another application which is not related to third party applications..Let me know the syntax or the method to call the small application???
suse
Follow kevin.blair's instructions in another answer to register a custom protocol scheme (say helloworld://) in your Hello World application, then use the UIApplication's openURL: method to open that URL (and the app that handles it, Hello World).
duncanwilcox
should i import helloworld application in my project or should i specify its path in my code, which is the proper way... also tel me where i'm i supposed to specify the URL in this function? -(Bool)application:(UIApplication *)application handleOpenURL:(NSURL *)url{}
suse
Pls do help me duncanwilcox!!!Pls....
suse
As I mentioned, kevin.blair's answer describes how one of your apps will register for a helloworld:// scheme, you don't use the app's path because you don't know where it will be installed on the phone, but you do know that opening a helloworld:// URL will launch it, so that's what you do. You "run" or "call" your Hello World application by opening a helloworld:// URL.
duncanwilcox
A: 
Kevin
hi kevin, My App is calling a Hello World application, tel me wher should i keep that Hello World app, should i import into my project or should i specify the path in URL as URLWithString:/Macintosh/user/xxx/Documents/Hello World?? which is the right way of doing it??
suse
Pls do reply kevin!!!!!!!!!
suse