アプリケーション起動時のURLハンドリング

| 4 Comments | 0 TrackBacks
iPhoneOSでは、各アプリケーションごとに、独自のURLスキームを定義できることは、iPhoneアプリケーション開発者のみなさんはご存知のことと思います。そのURLが、-[UIApplication openURL:]メソッドの引数で渡されると、対応するアプリケーションが起動されます。
起動される側のアプリケーションは、Application DelegateクラスでそのURLを受け取って、必要な処理を行います。
iPhoneOS 2.xまでは、URLのハンドリングは、application:handleOpenURL: メソッドでのみ行うことが可能でしたが。3.0からは、新しく追加された、application:didFinishLaunchingWithOptions: メソッドでも可能となりました。
このapplication:didFinishLaunchingWithOptions: メソッドのことを簡単にまとめると、以下のような感じになります。(詳細は、UIApplicationDelegate Protocol Reference を参照してください)
  • これまでの、applicationDidFinishLaunching: メソッドに、起動時のオプションパラメタを処理する機能が追加されたものである。
  • application:didFinishLaunchingWithOptions: メソッドが存在していると、applicationDidFinishLaunching: メソッドと、application:handleOpenURL: メソッドは、呼ばれなくなる。
  • 引数で渡される起動オプションは、NSDictionaryオブジェクトであり、push notificationまたは、URL起動時のパラメタが格納されている。
ということで、applicationDidFinishLaunching: メソッドと、application:handleOpenURL: メソッドを合成したようなものであると言えます。

URL起動の場合、起動オプションには、以下の2つのキーが存在します。
  • UIApplicationLaunchOptionsURLKey - 起動URLオブジェクト(NSURL)
  • UIApplicationLaunchOptionsSourceApplicationKey - 起動元アプリケーションのバンドル名
ふつうに、ホーム画面のアイコンをタップして起動された場合は、起動オプションはnilになります。

No TrackBacks

TrackBack URL: http://www.fourmeisters.com/mt/mt-tb.cgi/347

4 Comments

im loving the ipad personally. what do you think of it now? was it upto your standards?

Wow, Awesome post - アプリケーション起動時のURLハンドリング - FMSC iPhone Lab was a wonderful read. I'm such a newbie when it comes to all this, Thanks for this!

It does seem that everybody is into this kind of stuff lately. Don’t really understand it though, but thanks for trying to explain it. Appreciate you shedding light into this matter. Keep it up

I can read about this stuff all day long, thanks for the write up my friend! アプリケーション起動時のURLハンドリング - FMSC iPhone Lab was a wonderful read.