When performing a single sign-on for a mobile APP, you need to click the link in the browser to start the APP and upload the parameters to the corresponding interface in the APP for processing, now we will sort out the implementation process of calling Android and iOS applications through a browser and solidify it into a blog for query.
I. Use a browser to call Android applications
1) modify the configuration file AndroidManifest. xml and add the following configuration under the activity to be opened:
2) in HTML, add ssotest and click this link to open the APP.
3) Other apps can open the APP as follows:
StartActivity (new Intent (Intent. ACTION_VIEW, Uri. parse ("ssotest ://"))); |
4) if you want to pass the parameter, You can append it in the url, for example:
5) accept and parse parameters, and use the following code in the received Activity to obtain the parameters:
This. getIntent (). getScheme (); // get the Scheme name This. getIntent (). getDataString (); // retrieve all Uri paths and parse the strings according to the format. |
Ii. Use a browser to call the iOS app
1) modifyPlistFile to register external URLs
A: find info. plist of the project. B: Click the plus sign next to the information property list and select URL types from the list. C: Expand URL types, expand Item0, and change the URL identifier under Item0 to URL Scheme. D: Expand the URL Scheme and change the content of Item0 to ssotest (which can be customized) |
2) in HTML, add ssotest and click this link to open the APP.
3) If you want to accept the URL and perform special processing in the started APP, you can modify the project's AppDelegate. m and rewrite the openURL method as follows:
-(BOOL) application :( UIApplication *) application openURL :( NSURL *) url sourceApplication :( NSString *) sourceApplication annotation :( id) annotation { // You can use [url scheme] to obtain the defined Scheme name. // You can use [url absoluteString] to obtain the entire URL path and parse the transmitted data. } |