Swift: How to open a new app when UIButton is tapped

后端 未结 5 530
一生所求
一生所求 2020-11-29 10:18

I have an app and when a uibutton is clicked, I want to open another app that is already installed (i.e. Waze). How can I do such? Big thanks.

5条回答
  •  渐次进展
    2020-11-29 11:03

    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).

    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.

    For more info Refer here

提交回复
热议问题