如何在Mac OS X上从浏览器打开应用程序?

use*_*653 2 oauth callback openurl

我正在做一个Twitter Mac OS X应用程序,需要使用OAuth1.0.在请求oauth/access_token接口时,是否可以将oauth_callback参数用于此目的?

换句话说,如何在Max OS X上从浏览器打开应用程序?

Vik*_*pov 8

答案很明显:注册自定义URL方案

http://techblog.amphora-research.com/2010/03/registering-url-handlers-in-macos-x-cocoa-apps/

我的意思是说:

 1. Register the "twittercallbackformyapp://"
    scheme using the link above
 2. Set this callback in the 'access_token'
    HTTP request (oauth_callback parameter)
 3. Write the routine (handleOpenURL) to handle
    the 'twittercallbackformyapp://oauth_access_token=...&oauth_token_secret=...'
    which will be called after you register the handler
Run Code Online (Sandbox Code Playgroud)

关于oauth的许多问题都在这里解决:http://code.google.com/p/twitcurl/

上面的lib使用curl.您可以使用Cocoa本机网络API.

PS

这是关于如何注册URL处理程序的另一个描述:

http://mobiledevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

它适用于iPhone,但对于Mac,模式是相同的:将URL添加到应用程序的.plist文件中.