2

I have followed exactly the same tutorial Launch an app from within another (iPhone) but the code is only executing the else part and showing alert, So I am unable to open the second app. You can see the steps I have followed in the link above.

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:

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

}
Community
  • 1
  • 1
virat
  • 117
  • 1
  • 1
  • 7

1 Answers1

5

Add the custom Url in info.plist

1st image - In Your App which you are opening

2nd Image - In Your App which from you are opening

In Your App which you are opening

In Your App which from you are opening

For full explanation and code visit my blog here

Nilesh Jha
  • 1,626
  • 19
  • 35
  • i am opening the second app from first app...but i didnt get your point " In Your App which from you are opening" means i have to set the properties in the first app which you have shown in the second image – virat Sep 16 '16 at 10:13
  • i dont want to send the text just want to open the app – virat Sep 16 '16 at 10:15
  • Yeah the first image reference is for the app which yoou are trying to open. Just define a URL Scheme their. The second image is for the app from which you are tring to apen the another app.. Here You have to define QueryScheme withe the same String Name. – Nilesh Jha Sep 16 '16 at 10:15
  • and what does the NileshRecieverText ? – virat Sep 16 '16 at 10:17
  • This is same as iOSDevTips – Nilesh Jha Sep 16 '16 at 10:18
  • means the QueryScheme should be same in both the app na...i got confused because you have set NileshRaciever in one app and NileshRecieverText in other app so both needs to be same right – virat Sep 16 '16 at 10:19
  • In the first image(Not visible) under URLScheme Array. We have in string at item0 NileshRecieverText .. So you will replace it with iOSDevTips – Nilesh Jha Sep 16 '16 at 10:21
  • And how would i find that LSApplicationQuery ? – virat Sep 16 '16 at 10:21
  • No. dont Confuse with NileshReciever.. Just add NileshRecieverText in UrlSchema. – Nilesh Jha Sep 16 '16 at 10:22
  • The app from which you are trying to open another app, Just go to info.plist and type LSApplicationQueriesSchemes and then inside that array add NileshRecieverText at item0. – Nilesh Jha Sep 16 '16 at 10:24
  • there is no LSApplicationQueriesSchemes in my info.plist ? – virat Sep 16 '16 at 10:27
  • You can download the source code. If you are facing more issue. Then you can just copy and paste – Nilesh Jha Sep 16 '16 at 10:29
  • and if the app to be launched is not present in the device then how to open the itunes and show the app to the user so that he can download the app – virat Sep 16 '16 at 11:27
  • what code you have written. In the if condition you are checking its presence. And in the else condition you are showing AlertView. So their You can redirect user to itunes store by giving the link – Nilesh Jha Sep 16 '16 at 12:15