1. 在需要被启动的app中的plist文件, 右击Information Property List, 选择Add Row
2. 选择"URL types"作为键值
3. 展开的"Item1",为URL identifier提供一个值,这个值可以是任意的, 但是惯例是使用"反向域名(reverse domain name)"(例如:com.mycompany.myapp).
4. 右击"Item1", 选择"Add row"
5. 选择"URL Schemes"作为键值
6. 为这个"URL Schemes"输入对应的值(例如: "myapp://"那么就输入"myapp"). 这里可以输入多个不同的值.
7. 这是在另一个程序, 启动代码:
NSURL *url = [NSURL URLWithString:@"myapp:"];
[[UIApplication sharedApplication] openURL:url];
-----------------------
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=2
The 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!