简体   繁体   English

从另一个应用程序打开iOS应用程序

[英]open iOS app from another app

I am trying to open my app MyApp from another app, I've already defined the custom url for MyApp (ie myapp:// ). 我正在尝试从另一个应用程序打开我的应用程序MyApp ,我已经为MyApp定义了自定义网址(即myapp:// )。

If I write myapp:// in safari and click on go it will open MyApp . 如果我在safari中编写myapp://并单击go,它将打开MyApp Now what I want is a simple app with only a UIButton "Launch MyApp" and when I click it MyApp will launch. 现在,我想要的是一个只有UIButton “启动MyApp”的简单应用程序,当我单击它时, MyApp将启动。

I tried it by doing this: 我这样做来尝试了:

-(IBAction)launchMyApp:(id)sender
{
    NSString *mystr=[[NSString alloc] initWithFormat:@"myapp://"];
    NSURL *myurl=[[NSURL alloc] initWithString:mystr];
    [[UIApplication sharedApplication] openURL:myurl];
}

but nothing happened. 但是什么也没发生。 If it is possible to implement this functionality please provide me the code. 如果可以实现此功能,请提供代码。

Thanks 谢谢

Solved the problem 解决了问题

I don't know how but it worked with the same code I've written in the question: 我不知道如何使用,但是它可以与我在问题中编写的相同代码一起使用:

-(IBAction)launchMyApp:(id)sender
{
    NSString *mystr=[[NSString alloc] initWithFormat:@"myapp://"];
    NSURL *myurl=[[NSURL alloc] initWithString:mystr];
    [[UIApplication sharedApplication] openURL:myurl];
} 

If it works in Safari, it may work in a UIWebView . 如果可以在Safari中使用,则可以在UIWebView Try displaying the page you used in Safari in a UIWebView and see if it wokrs ! 尝试在UIWebView显示您在Safari中使用的页面,看看它是否正常!

使用一些实际的URI,而不仅仅是方案,然后不使用任何内容,例如myapp://launch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM