Detect whether there is an Internet connection available using Worklight - ibm-mobilefirst

How can I check wheather device has connected to internet using IBM Worklight

Yes.
Worklight provides the following API method: WL.Device.getNetworkInfo
For example, check for Internet connection on application startup and do actions based on the result.
In common\js\main.js:
function wlCommonInit() {
WL.Device.getNetworkInfo(function (networkInfo) {
alert (networkInfo.isNetworkConnected);
if (networkInfo.isNetworkConnected) { // if true, then
// connect to the Worklight Server or do something else...
}
});
IBM provides a Knowledge Center with complete API reference and more.
Please review it.

Related

IBM mobileFirst IOS application screen blackout after direct update

Details of Project :
Application Framework - Ionic V3.0
IBM MobileFirst server(devKit) - Product version: 8.0.0.00-20170911-123510
Application Mobilefirst version -
config.xml -
mfp:platformVersion -8.0.0.00-20170218-003050
plugin name="cordova-plugin-mfp" spec="8.0.2017021815"
It's working fine in android. But in IOS, after finishing of soft update, application screen goes blank (black screen). After killing and restart of application, it's started working fine.
I have implement Direct update feature in mobilefirst 8 application as below :
// Direct Update - Used to trigger a request to the MobileFirst Server, to check for updated web resources.
WLAuthorizationManager.obtainAccessToken()
.then(
function () {
console.log("*** Obtained token successfully.");
},
function () {
console.log("*** Failed obtaining token.");
}
);
Reference : https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/application-development/direct-update/#secure-direct-update
This is perhaps has to do with the fact that Ionic now uses the WKWebView by default. See https://ionicframework.com/docs/wkwebview/
And it is a known limitation with MobileFirst Direct update on the WKWebview. See https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/product-overview/release-notes/known-issues-limitations/#wkwebview-support-for-ios-cordova-applications
As mentioned in the above link, use the wkwebview-engine-localhost plugin to ensure Direct update continues to work.
It's fixed in latest IBM MobileFirst version.

Why Doesn't Direct Update happen on IBM MobileFirst Platform?

I have developed a hybrid sample app on MobileFirst Platform 7.0. When I make any change in the .html file, direct update won't appear on the client mobile application (Android and iOS). Am I missing something? I have already deployed the .wlapp file on the server.
Direct Update will only work if the application connects to the server. Make sure that you are using the API method WL.Client.connect(), otherwise even if deploying an updated .wlapp to the server, the update will not be received in the application.
You say you haven't updated the .wlapp; you should. The Direct Update process works by fetching updated web content (HTML/CSS/JS/etc.) from inside the .wlapp. As Idan says, you also need to make sure your client is connecting to the server.
In order to begin communicating with MobileFirst Server you need to call WL.Client.connect() API method once the application start.
For Example in a main.js file :
WL.Client.connect({
onSuccess: function(){
console.log("App is connected to the server...");
// Call some methods ...
},
onFailure: function(){
alert("unable to connect to the server...");
}
});
Make sure that you have built the .wlapp file with the correct configuration(Deployment target) and that's deployed successfully in the server.

how to check network availablity in mobilefirst

I am developing an mobile application where I need to check if the device is connected to internet and if it is not connected then it should show an popup saying you are not connected to internet and it should have a option for settings on clicking which it should to take the settings of the mobile where the user can turn on the WIFI or mobile internet
There are two questions:
need to check if the device is connected to internet and if it is not
connected then it should show an popup saying you are not connected to
internet
You can use the WL.Device.getNetworkInfo API method, for example:
function wlCommonInit() {
WL.Device.getNetworkInfo(function (networkInfo) {
if (networkInfo.isNetworkConnected) {
alert ("connected");
} else {
alert ("not connected");
}
});
}
should have a option for settings on clicking which it should to take
the settings of the mobile device where the user can turn on the WIFI or
mobile internet
This could probably be implemented using a Cordova plug-in. Find a Cordova plug-in that allows you to open the settings screen of the device or even deeper, the settings > network setting screen of the device, there the user could do it. However, I would simply tell the user to go there on his own and not implement that... your choice, more complicated.

IBM Worklight - How to change the url of the worklight server dynamically

I need to customize a screen where the user can inform the worklight server ip in client-side.
I can change the url connection dynamically?
I know that pressing the menu button in android, there is the option of informing the url, but i want custom screen.
Technically speaking it is possible to change the Worklight Server URL that the application connects to, but things can and likely will go wrong and it is absolutely not supported by IBM Worklight.
As for creating some UI for it, that's on you.
See this answer by Anton: Re-route/Divert some WL.Client Adapter Invocation traffic to WL Server through different URL (for PCI payment and security requirements)?
Also see the following questions:
IBM Worklight - How to use Custom Server URL?
IBM Worklight - How to customize an app after creating its .api/.apk?
Worklight Apps pointing to different Worklight Servers
For Worklight v6.1, you can set below properties dynamically:
WL.StaticAppProps.APP_SERVICES_URL = your URL + WL.StaticAppProps.POSTFIX_APP_SERVICES_URL;
WL.StaticAppProps.WORKLIGHT_ROOT_URL = your URL + WL.StaticAppProps.POSTFIX_WORKLIGHT_ROOT_URL;
WL.StaticAppProps.WORKLIGHT_BASE_URL = your URL;
if you dig into the worklight.js file there is a function "setWLUrl(url)" that can be use to chnange the serevr URL.
call it like this and its done
setWLUrl("http://"+yourServerIP+":PORT");
its kind a hack but i think it should not have anny issue since its a function within there api.
Good Luck

Connect to WiFi programmatically in ios

My question is about private API in IOS. Is there some API to manage WiFi connection? For example I'm using Apple80211.framework to scan WiFi networks but it's unusable for connecting.
My app isn't for appstore.
We can programmatically connect wifi networks after iOS 11 public API. You can connect wifi using SSID and password like following.
Swift
var configuration = NEHotspotConfiguration.init(ssid: "wifi name", passphrase: "wifi password", isWEP: false)
configuration.joinOnce = true
NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
if error != nil {
//an error occurred
print(error?.localizedDescription)
}
else {
//success
}
}
Don't forget import NetworkExtension.
I ran into this issue last year and after quite a bit of digging I came across a helpful example called SOLStumbler. For this app to work your device must be jailbroken. I modified SOLStumbler and threw up a sample app on github. It uses the IPConfiguration bundle to access Apple80211 framework, which allows you to associate to a network. The readme contains the custom build instructions.
https://github.com/devinshively/wifiAssociate
No need for private API any more! With iOS 11, Apple provided a public API you can use to programmatically join a WiFi network without leaving your app.
The class you’ll need to use is called NEHotspotConfiguration.
To use it, you need to enable the Hotspot capability in your App Capabilities (Adding Capabilities). Quick working example :
NEHotspotConfiguration *configuration = [[NEHotspotConfiguration
alloc] initWithSSID:#“SSID”];
configuration.joinOnce = YES;
[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:nil];
This will prompt the user to join the “SSID” WiFi network. It will stay connected to the WiFi until the user leaves the app.
This doesn't work with the simulator you need to run this code with an actual device to make it work.
More informations here :
https://developer.apple.com/documentation/networkextension/nehotspotconfiguration
It's possible in any version of iOS which can load a configuration profile: the app needs to generate a profile with the desired network credentials, and host a web server which provides the profile to Mobile Safari.