How does the Apple iTunes web site launch the iTunes application on my computer when I click the blue “Launch iTunes” button?

大兔子大兔子 提交于 2019-12-18 11:09:29

问题


This is new to me as a desktop developer.

If I could figure out how this is accomplished, it may be relevant to some research I'm doing, specifically how to migrate thick desktop apps to a web implementation.

The more forms-oriented and lightweight graphics I can figure out, but heavyweight 3D graphics still requires some form of non-browser application.

As nearly as I can determine, iTunes installs some form of new protocol handler on my machine, corresponding to "itms", in place of "http".

This is cool and mysterious to me, almost magical. Any help or suggestions for additional reading materials and/or resources would be very welcome.


回答1:


You can register "protocol handlers" with some browsers. I think there's a place in the operating system where you can regsiter your own.

See

  • http://msdn.microsoft.com/en-us/library/dd588696(office.11).aspx
  • http://blog.ryaneby.com/archives/firefox-protocol-handlers/

Creating new ones in firefox: http://ajaxian.com/archives/creating-custom-protocol-handlers-with-html-5-and-firefox

In safari: http://discussions.apple.com/thread.jspa?threadID=1280989

Special "mobile protocol handlers" are used extensively in the iPhone/iPod to launch the phone dialler, email sending, google maps and so on... http://www.iphonedevfaq.com/index.php?title=Protocols

Here's an example of how to reconfigure the mailto: protocol handler to trigger gmail rather than an external mail client: http://lifehacker.com/392287/set-firefox-3-to-launch-gmail-for-mailto-links




回答2:


Simple.

<a href="itunes:///">Open iTunes</a>

Most apps now-a-days have "Custom URL Schemes" For Example - Coda (http://panic.com/coda) you can add snippets of code via:

<a href="codaclips:///<<**Title:NAME**>>blabla">Add Clip</a>



回答3:


In Windows this is called a Pluggable Protocol Handler. This article on CodeProject shows how to implement a pluggable protocol handler on Windows.

Note, this is more involved then just registering a new protocol in the registry, such as myprotocol:// and having it start a specific exe whenever a myprotocol:// anchor is clicked.

It actually allows your application to receive and process the request and to create response data dynamically. If your protocol will also be called programmatically this is usually important.

This may be overkill for your situation however it is handy to know about.




回答4:


The easiest way is to register a filetype to your application (also called File Association), for example ".myp" and when the user press "start myapp" on the site it downloads a file "startapp.myp".

Windows will then look at the extention of the file and find that it is registered to your app and start your application with the file as a command-parameter. Your app can then read the file and do stuff depending of it contents.

Here are code to register a filetype to your application done in VB.Net:
(Example is taken from http://www.developerfusion.com/article/36/file-assocation/2/ but copied here for persistent reason, check original site for comments)

'// Registry windows api calls
Private Declare Function RegCreateKey& Lib "advapi32.DLL" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpszSubKey As String, ByVal lphKey As Long)
Private Declare Function RegSetValue& Lib "advapi32.DLL" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpszSubKey As String, ByVal fdwType As Long, ByVal lpszValue As String, ByVal dwLength As Long)
'// Required constants
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const MAX_PATH = 256&
Private Const REG_SZ = 1

'// procedure you call to associate the tmg extension with your program.
Private Sub MakeDefault()
    Dim sKeyName As String  '// Holds Key Name in registry.
    Dim sKeyValue As String  '// Holds Key Value in registry.
    Dim ret As Long    '// Holds error status if any from API calls.
    Dim lphKey As Long    '// Holds created key handle from RegCreateKey.

    '// This creates a Root entry called "TextMagic"
    sKeyName = "TextMagic" '// Application Name
    sKeyValue = "TextMagic Document" '// File Description
    ret = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey)
    ret = RegSetValue&(lphKey&, Empty, REG_SZ, sKeyValue, 0&)

    '// This creates a Root entry called .tmg associated with "TextMagic".
    sKeyName = ".tmg" '// File Extension
    sKeyValue = "TextMagic" '// Application Name
    ret = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey)

    ret = RegSetValue&(lphKey, Empty, REG_SZ, sKeyValue, 0&)

    '//This sets the command line for "TextMagic".
    sKeyName = "TextMagic" '// Application Name
    If Right$(App.Path, 1) = "\" Then
        sKeyValue = App.Path & App.EXEName & ".exe %1" '// Application Path
    Else
        sKeyValue = App.Path & "\" & App.EXEName & ".exe %1" '// Application Path
    End If
    ret = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey)
    ret = RegSetValue&(lphKey, "shell\open\command", REG_SZ, sKeyValue, MAX_PATH)
End Sub

Private Sub Form_Load()
    '// ensure we only register once. When debugging etc, remove the SaveSetting line, so your program will
    '// always attempt to register the file extension
    If GetSetting(App.Title, "Settings", "RegisteredFile", 0) = 0 Then
        '// associate tmg extension with this app
        MakeDefault()
        SaveSetting(App.Title, "Settings", "RegisteredFile", 1)
    End If
   '// check command line argument:
    If Command$ <> Empty Then
        '// we have a file to open
        '// Fetch the file name from Command$ and then read the file if needed.
    End If

End Sub



回答5:


Just a follow-up for those who answered.

Turns out that the situation is somewhat complicated. Although about:config is available for FireFox, making the appropriate entries just doesn't work.

This link: http://support.mozilla.com/tiki-view_forum_thread.php?locale=fr&forumId=1&comments_parentId=74068 describes problems for Linux, but I can verify that the same problems also occur under Windows.

To make this work under Windows, I had to create a .REG file which contains the appropriate information, according to this link: http://kb.mozillazine.org/Register_protocol#Windows

Now it works!

Thanks for all the responses.



来源:https://stackoverflow.com/questions/1780211/how-does-the-apple-itunes-web-site-launch-the-itunes-application-on-my-computer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!