on 2024 Jun 21 4:17 PM
Hello MDK Community,
I am currently developing an application using the SAP Mobile Development Kit (MDK) and I am facing a challenge in retrieving the host name (of mobile devices) during runtime.
The objective is to programmatically determine the host name of the device within my MDK application. This information is critical to implement custom logic for environment-specific routing.
Thus far, I have:
Additionally, I'm aware that for the WebApp, it's possible to retrieve the host by using the following JavaScript line:
const hostnameElements = window.location.hostname;
//output: ‘xxxxx-dev-mobile-appId-12345678.cfapps.euxx.hana.ondemand.com'However, this method work only on WebApp and fail to function on mobile devices, as it's not compatible with NativeScript used by the MDK on mobile platforms.
What I need is an alternative method that works on MDK clients within a mobile environment.
To provide some background on the issue: The purpose of retrieving the hostname is to determine the environment in which the app is running. For instance, if the hostname contains the term "dev," then the app should open a specific URL associated with the Development environment. Similarly, if the hostname contains "qas" or "prod," it should open a link tailored for the QAS or Prod environments respectively.
If anyone has insights on accessing the mobile host information in an MDK environment or knows of any workaround to achieve a similar result as window.location.hostname on the web, your guidance would be greatly valued.
For reference, I'm using SAP Mobile Services for the backend orchestration and the latest MDK client version.
Thank you in advance for your assistance!
Best regards, Khaled
Request clarification before answering.
Have you tried calling clientAPI.getMobileServiceEndpointUrl()? You can also call clientAPI.getMobileServiceAppId() to get the app id in mobileServices as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It works with
const platformModule = clientAPI.nativescript.platformModule; // Check whether the platform is web or mobile
const hostname = platformModule.isWeb ? window.location.hostname : context.getMobileServiceEndpointUrl();Thanks @Bill for the input!
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 6 | |
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.