首页 文章

无法从另一个(iPhone)启动应用程序

提问于
浏览
2

我已经按照完全相同的教程Launch an app from within another (iPhone)但是代码只执行else部分并显示警告,所以我无法打开第二个应用程序 . 您可以在上面的链接中看到我所遵循的步骤 .

假设我们有两个名为FirstApp和SecondApp的应用程序 . 当我们打开FirstApp时,我们希望能够通过单击按钮打开SecondApp . 这样做的解决方案是:

在SecondApp中

转到SecondApp的plist文件,你需要添加一个带有字符串iOSDevTips的URL Schemes(当然你可以写另一个字符串 . 这取决于你) .

2 . 在FirstApp中

使用以下操作创建一个按钮:

- (void)buttonPressed:(UIButton *)button
{
  NSString *customURL = @"iOSDevTips://";

  if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
  {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
  }
  else
  {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"URL error"
                              message:[NSString stringWithFormat:@"No custom URL defined for %@", customURL]
                              delegate:self cancelButtonTitle:@"Ok" 
                              otherButtonTitles:nil];
    [alert show];
  }

}

1 回答

  • 4

    在info.plist中添加自定义Url

    第1张图片 - 在您正在打开的应用程序中

    第二张图片 - 在您的应用程序中,您正在打开它

    In Your App which you are opening

    In Your App which from you are opening

    有关完整说明和代码,请访问我的博客here

相关问题