自定义url打开应用 iphone
2012-09-13 15:32
302 查看
file located in your application’s project folder (NOTE: this is the same file you would change to define a custom icon).By default, when opened, XCode will edit the file in a graphical UI. It is possible to edit the info.plist file directly in Text mode which may be easier for some people.Step 1. Right-Click and “Add Row”Launching Your iPhone App Via Custom URL Scheme
form http://mobiledevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html One of the coolest features of the iPhone SDK is an application’s ability to “bind” itself to a custom URL scheme and for that scheme to be used to launch itself from either a browser or from another application on the iPhone. Creating this kind of binding is so simple, its almost criminal not to use it in your application!Before you get started, you need to figure out how you want you application to respond to the URL. The simplest way to use custom schemes is to just “wake up”; but it is also possible to pass information to the application via the URL, and in so doing, enable the application to do different things when woken up.Registering Custom URL Schemes
Regardless of what you want to do once your application is started, the first step is to register a custom URL scheme with the iPhone. This is done via the [code]info.plist
![](http://mobiledevelopertips.com/wp-content/uploads/2008/12/screen-capture1.png)
![](http://mobiledevelopertips.com/wp-content/uploads/2008/12/screen-capture-11.png)
![](http://mobiledevelopertips.com/wp-content/uploads/2008/12/screen-capture-21.png)
![](http://mobiledevelopertips.com/wp-content/uploads/2008/12/screen-capture-31.png)
![](http://mobiledevelopertips.com/wp-content/uploads/2008/12/screen-capture-4.png)
![](http://mobiledevelopertips.com/wp-content/uploads/2008/12/screen-capture-6.png)
Optionally Handle the URL
Now that the URL has been registered. Anyone can start the application by opening a URL using your scheme.Here are a few examples …myapp:// myapp://some/path/here myapp://?foo=1&bar=2 myapp://some/path/here?foo=1&bar=2The iPhone SDK, when launching the application in response to any of the URLs above, will send a message to the UIApplicationDelegate.If you want to provide a custom handler, simply provide an implementation for the message in your delegate. For example:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { // Do something with the url here }A common technique is to parse the URL passed in and pull from it the parameters that will be used by various views in the application and store them in the User Preference. Below is an example where we store the URL as a value parameter “url” in just such a manner …
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { if (!url) { return NO; } NSString *URLString = [url absoluteString]; [[NSUserDefaults standardUserDefaults] setObject:URLString forKey:@"url"]; [[NSUserDefaults standardUserDefaults] synchronize]; return YES; }Now you have everything you need to enable others to wake-up your application and even pass it information! Enjoy!
要iphone真机的浏览器才行 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 关闭打开时lanchOptions有信息,自己log看key
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url任何时候都有信息,包括关闭打开,home返回等
相关文章推荐
- 在 iPhone 应用里自定义一个弹出窗口
- 在iPhone应用里直接打开app store 评论页面的方法
- android/iPhone:如何从browser直接打开应用程序或者打开应用商店(如果没有应用程序)
- iPhone地图应用开发以及自定义Annotation
- IPHONE应用开发 - 打开和关闭键盘
- 在iPhone应用的table cell中添加自定义布局view
- [ios]iPhone地图应用开发以及自定义Annotation [转]
- 在iPhone应用里直接打开app store 评论页面的方法
- UTI iPhone支持依文件后缀名打开应用
- android/iPhone:如何从browser直接打开应用程序或者打开应用商店(如果没有应用程序)
- 在iPhone应用中使用自定义字体
- 在iPhone应用中使用自定义字体
- 在iPhone应用里直接打开app store 评论页面的方法
- iOS:开放平台引用(一)--应用外打开app / respond to a custom URL scheme
- 在iPhone应用中使用自定义字体
- iOS 自定义 URL Scheme,点击url打开app
- Android通过URL/URI来打开我们的应用
- 从浏览器或者App调起iOS应用之IOS自定义URL
- [ios]iPhone地图应用开发以及自定义Annotation [转]