tags:

views:

251

answers:

3

While working on iphone security architecture, i came to know that i can run applications from other applications in iphone. referring to the following url http://iphonedevelopertips.com/cocoa/launching-other-apps-within-an-iphone-application.html

for example, i can put a link in a website with following hyperlink skype:// will result skype to run and call at particular number. Now i have few concerns here.

  • is there a shell running in background in iphone, so that it allows other application to run basic app commands.
  • if the above statement is true then how can i enable or run commands directly into iphone shell?
  • if above statements are false, then could you please explain how these commands are being executed?
  • is this part of iPhone SDK? or this funcationality is iPhone OS
+4  A: 

This is functionality of the iPhone OS. Applications register themselves as URL Handlers for particular protocols. In this case the Skype app is registered to handle skype:// URL protocols.

  • An Application registers itself as a protocol handler via the CFBundleURLTypes key in it's Info.plist. See here.
  • The OS reads this key when your application is installed.
  • Whenever a URL for that protocol is encountered and tapped on, the OS will launch your App and your Application Delegate will be sent the application:handleOpenURL: message.
  • It is then up to your Application to correctly decode the URL and perform the correct action.

PS. There is virtually identical functionality available in Mac OS X, with the additional possiblity for URLs to be sent to already running applications.

Alan Rogers
that makes sense. One last question to. if i put the command skype:// in browser address bar then it does not work (i.e does not open skype) but if i make it a link in website then it works fine. Can someone explain it?
That should work, and it works for me. What OS version are you on?
Alan Rogers
A: 

what alee is asking about, I guess, is the "mailto://". when you put this in the browser address bar it does not do anything, but if you put it as a link and click on it, it lunches the mail app. why does the mail app have this behavior?

+1  A: 

A shell can be spawned with system or popen etc. Of course, because the apps are sandboxed, fork() is denied so the shell won't be accessible from any AppStore apps.

However, there are lots of stuff running in background on the iPhoneOS. One of them is SpringBoard.app, which is the "home screen" you see on start up. Actually SpringBoard.app is responsible for much more stuff than just displaying the home screen, one of them is to receive and deliver URL requests.

The registration process has been described by @Alan. But under hood, when a URL request is issued by an app, the following will happen:

  1. The app, knowing itself cannot handle a particular URL, calls -[UIKit openURL:] to delegate the open request to others.
  2. UIKit will package the URL request into a GSEvent (an IPC mechanism), and then dispatch it to SpringBoard.
  3. SpringBoard, receiving this GSEvent, calls -[SpringBoard applicationOpenURL:].
  4. This method will check if the URL is well-form and safe (stuff like tel://*5005*78283# will be rejected, for example). If it is valid, the action will be performed (dial a number, subscribe to a calendar, open an app, etc.)
KennyTM