-1

My app is called Labmed, where a button will appear to open the "LAB Befund" App. If "LAB Befund" is already installed, open the app, instead of going to the AppStore.

Code:

NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setValue:ltvController forKey:@"LAB Befund"];
[array addObject:dic];

NSString *LABAppURL = "LAB Befund://openApp?param1=XXX&param2=YYY";
NSString *LABWebURL = @"https://itunes.apple.com/de/app/lab-befund/id1019115877?mt=8";


BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:LABWebURL]];


NSLog(@"can open: %d", canOpenURL);

NSString *url = canOpenURL ? LABAppURL : LABWebURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

That's what I found in the internet so far. It is opening the Appstore EVERY time, of cause the app is installed.

I added the following statements to my .plist:

URL types
   Item0
      URL Schemes
         Item0
      URL Identifier

CanOpenURL return "NO".

CONCLUSION: Assuming two apps TestA and TestB. TestB wants to query if TestA is installed. “TestA” defines the following URL scheme in its info.plist file:

<key>CFBundleURLTypes</key>
<array>
<dict>
    <key>CFBundleURLSchemes</key>
    <array>
        <string>testA</string>
    </array>
</dict>

The second app “TestB” tries to find out if “TestA” is installed by calling:

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"TestA://"]];

But this will normally return NO in iOS9 because “TestA” needs to be added to the LSApplicationQueriesSchemes entry in TestB’s info.plist file. This is done by adding the following code to TestB’s info.plist file:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>TestA</string>
</array>

And that's how it worked for me.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Cyu.
  • 81
  • 1
  • 1
  • 7
  • Did you register [a custom URL scheme](https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html) in your app? – Tamás Sengel Jan 29 '18 at 15:37
  • Ahh, not as far as i remember. I will follow https://coderwall.com/p/mtjaeq/ios-custom-url-scheme. Edit: So I added these things to the .plist but nothing changed. – Cyu. Jan 29 '18 at 15:47
  • Do not say "I added these things to the .plist". Don't talk _about_ your .plist. _Show_ it. Edit your question to show what you've done. It is your responsibility to give enough information to allow others to reproduce the problem. – matt Jan 29 '18 at 16:45
  • You do not want to setup a custom URL scheme in your Info.plist. You do not need to provide a custom URL scheme for your own app. You are attempting to launching someone else's app. – rmaddy Jan 29 '18 at 17:00

1 Answers1

1

You must replace in LABAppURL the "LAB Befund" with the handler (URL Schema) you have put in Info.plist of LAB Befund.

Shebuka
  • 3,148
  • 1
  • 26
  • 43
  • My app is called Labmed, where a button will appear to open the "LAB Befund" App. So when I am going to replace the URL with the URL Schema from my Info.plist, the programm will open my LAB Befund App ?? – Cyu. Jan 30 '18 at 07:08
  • Ok, now we have all information... You need to replace the url with URL Schema from LAB Befund Info.plist – Shebuka Jan 30 '18 at 08:29
  • I added the following statements to my .plist: URL types Item0 URL Schemes Item0 URL Identifier So now I have to take the name I gave the appright there in the OpenUrl statement? – Cyu. Jan 30 '18 at 08:34