问题
I followed http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html instruction to open app1(GlassButton) within app2(FontTest).
The open method of FontTest as following:
-(void)open {
BOOL res = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"glassbutton://"]];
if (res) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"glassbutton://"]];
}
}
The value of "res" is "YES", but nothing happen after openURL method be called. The info-list of "FontTest"as following:
URL Schemes: glassbutton
URL identifier: com.yourcompany.glassbutton
I tried to open twitter and facebook apps by "twitter://" and "fb://" successfully. But I do not know why I cannot open this small app. I'm not sure whether any thing/step wrong or missing? Need I handle - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
for FontTest, if yes, how to handle it? Could you please kindly help me? Thanks in advance!
回答1:
To request the launch of your app use something like this:
NSString *urlString= @"glassbutton://com.yourcompany.glassbutton";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
Then, in the glassbutton app, you'll need to handle any special behavior within the app delegate method:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
//your app specific code here for handling the launch
return YES;
}
Note that within the app you are opening the above delegate method will only get called AFTER the following method is called:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Handle accordingly, good luck.
来源:https://stackoverflow.com/questions/6123194/how-to-use-uiapplication-sharedapplication-openurl-open-other-app