如何使用[[UIApplication sharedApplication] openURL:]打开其他应用程序?

时间:2011-05-25 10:43:56

标签: iphone uiapplication openurl

我按照http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html指令在app2(FontTest)中打开app1(GlassButton)。

FontTest的open方法如下:

-(void)open {

  BOOL res = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"glassbutton://"]];

  if (res) {

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"glassbutton://"]];

  }

}

“res”的值为“YES”,但在调用openURL方法后没有任何反应。 “FontTest”的信息列表如下:

URL Schemes: glassbutton

URL identifier: com.yourcompany.glassbutton

我试图通过“twitter://”和“fb://”成功打开twitter和facebook应用。但我不知道为什么我不能打开这个小应用程序。我不确定是否有任何事情/步骤错误或缺失?我需要为FontTest处理- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url,如果是,如何处理它?能帮助我吗?提前谢谢!

1 个答案:

答案 0 :(得分:3)

要请求启动您的应用,请使用以下内容:

NSString *urlString= @"glassbutton://com.yourcompany.glassbutton";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

然后,在glassbutton应用程序中,您需要处理app delegate方法中的任何特殊行为:

 - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    //your app specific code here for handling the launch

    return YES;
 }

请注意,在app中打开上面的委托方法只会在调用以下方法后调用:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

相应处理,祝你好运。

相关问题