1, requirements,

Work may have such a requirement, that is, the mobile browser load an H5 page, click to open a certain APP, such as wechat. In this case, the URL Scheme is usually used for configuration forward. So what is a URL Scheme? Simply put: it’s a page-hopping protocol.

2. URL Scheme protocol

URL Scheme is an in-page jump protocol, which is a very good implementation mechanism. By defining your own Scheme protocol, you can easily jump to each page in app. Through scheme protocol, the server can customize to tell App which page to jump to, customize to jump to page through notification bar message, and jump to page through H5 page, etc.

Every APP in the iPhone has a sandbox. Apps are islands of information and cannot communicate with each other. However, iOS apps can register their own URL Scheme, which is designed to facilitate the call between apps.

A URL Scheme must uniquely identify an APP. If your URL Scheme conflicts with another APP’s URL Scheme, your APP may not be launched. Because when your APP is installed, your URL Scheme has already been registered in the system. Full URL Scheme format:

stars://host:8088/pageDetail? pageId=102Copy the code

1. Stars: indicates the Scheme protocol name, which can be customized. 2. PageDetail: indicates the name of the page to be forwarded. PageId: indicates the parameter to be transferred. 5.8088: indicates the port name of the page to be forwarded

3. Specific usage configuration

Android configuration

<activity ... <! <intent-filter> <intent-filter> <! --> <data android:host="host"
                    android:path="/pageDetail"
                    android:port="8088"// Android :scheme="stars"/ > <! The following lines must also be set --> <! <category Android :name= --> <category Android :name="android.intent.category.DEFAULT"/>
                <action android:name="android.intent.action.VIEW"/ > <! -- Add this item if you want the app to launch from a browser connection --> <category Android :name="android.intent.category.BROWSABLE"/>
            </intent-filter>
        </activity>
Copy the code

IOS configuration

Just configure the info.plist file, just configure URL Schemes and the identifier is optional

4. Precautions

If your app is invoked from an external URL it has registered with, if you want to listen for incoming intents in an existing MainActivity, In androidmanifest.xml, set the launchMode of the MainActivity to singleTask

<activity
  android:name=".MainActivity"
  android:launchMode="singleTask">
Copy the code