How to use [[UIApplication sharedApplication] openURL:] open other app?

我怕爱的太早我们不能终老 提交于 2019-12-03 19:42:14

问题


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

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