Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL types with multiple bundle identifier for iOS app

I'd like my iOS project to handle multiple URL types and multiple bundle identifiers, so I can install 2 versions of the app on the same device.

I have 2 different bundle IDs: com.mycompany.myapp and com.mycompany.myapp-test

I'm registering 2 URL types for both bundle identifiers in the Info.plist file

enter image description here

I generate 2 builds with the 2 bundle identifiers and installing both apps on the same device. Then I'm trying to reach my apps using 2 urls: myapp://feed and myapp-test://feed.

However for some reason, I cannot open myapp-test and it always opens myapp when I click on both links.

There is certainly something wrong in the way I handle this so I'm wondering how I can manage multiple bundle ID with multiple URL scheme within the same Xcode project?

Thanks

like image 632
alexmngn Avatar asked Sep 03 '25 16:09

alexmngn


2 Answers

A bit of investigation produced a few solutions.

Automatic

Use $(PRODUCT_BUNDLE_IDENTIFIER) for both identifier and scheme then open each app using URL like com.mycompany.myapp://. This will always work regardless on how many targets, schemes or build settings you have.

Semi-automatic

Set user-defined variables. You need to put these variables in your info.plist file in order to reference them. This approach is more flexible but you have to write the scheme names by hand (only once). Actually it's the way I chosen in my applications.

By hand

This is more a workaround than a proper solution but 100% works in all cases: set identifier and scheme before build each bundle.

For example if you have identifier/scheme pairs like com.mycompany.myapp/myapp and com.mycompany.myapp-test/myapp-test then do the following:

  1. Set identifier com.mycompany.myapp and scheme myapp then build app bundle myapp
  2. Set idientifier com.mycompany.myapp-test and scheme myapp-test then build app bundle myapp-test

This way you should be able to open each bundle calling the relative scheme. Though you will need to change the URL types before each build. Personally I would never do like this.

like image 156
bitsmanent Avatar answered Sep 05 '25 06:09

bitsmanent


Make sure that:

1) for app with com.mycompany.myapp bundle ID you registered mayapp schema, there should be no myapp-test schema registered;

same time,

2) for app with com.mycompany.myapp-test bundle ID you registered myapp-test schema, there should be no myapp schema registered.

If I've got the problem correctly, the reason of such a behavior is both your apps are registered for both schemes. When you try to open some URL (myapp-test://... or myapp://... ) iOS detects that there is more then one app registered and picks first to handle it.

It's not needed to register schemes that you intended to open - you need to register schemes you're going to handle.

Hope this helps.

like image 45
Igor B. Avatar answered Sep 05 '25 06:09

Igor B.