Launch an app from within another (iPhone)

后端 未结 14 1644
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 01:14

Is it possible to launch any arbitrary iPhone application from within another app?, For example in my application if I want the user to push a button an

14条回答
  •  抹茶落季
    2020-11-22 01:34

    I found that it's easy to write an app that can open another app.

    Let's assume that we have two apps called FirstApp and SecondApp. When we open the FirstApp, we want to be able to open the SecondApp by clicking a button. The solution to do this is:

    1. In SecondApp

      Go to the plist file of SecondApp and you need to add a URL Schemes with a string iOSDevTips(of course you can write another string.it's up to you).

    enter image description here

    2 . In FirstApp

    Create a button with the below action:

    - (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];
      }
    
    }
    

    That's it. Now when you can click the button in the FirstApp it should open the SecondApp.

提交回复
热议问题