Search code examples
androidiosibm-mobilefirst

Worklight 6.2: Unable to connect to Worklight App Server using WL.Client.Connect


Im facing this issue for 3 days already. Help needed.

Im creating a hybrid app with push notification features for both Android and iOS using Worklight V6.2. Different issue found on these 2 environment.

Below is steps to create and deploy apps to remote server.

  1. Create hybrid app
  2. Include WL.Client.Connect in /common/js/main.js. Include also function for onSuccess and onFailure.
  3. Created new environment - tick box Android, iPhone, iPad
  4. Run As -> Build all environment (Successful)
  5. Change the Build Setting and Deploy Target. Tick on Build the application to work with a different worklight server. Enter the IP (https://:) and contextroot(/MyPushProject).
  6. Run As -> Run on worklight development server.
  7. Open remote server Worklight console
  8. Deploy XXXXX-all.wlapp file (Successful)
  9. Export android apps to apk file. Install in android apps.
  10. Run as Xcode Project -> Run in authorized ipad and iphone.

Below is the output for both platform. I didnt test it using Android emulator due to slowness and capabilites of my laptop.

Android: Build and deploy to remote server successful. Viewed using web browser.

Preview using android. WL.Client.Connect received this error - https://XX.XX.XXX.XXX:XXXX/MyPushProject/apps/services/api/MyPushApps/android/init. Failed to load resource: the server responded with a status of 401 (Unauthorized)

iOS (iPad & iPhone): Build and deploy to remote server successful. Viewed using web browser.

Preview using iphone and ipad. WL.Client.Connect received successful to connect to Worklight Server. Build apps using Xcode 7.1 run into iPad and iPhone (iOS 9.0) and received error "Failed to connect to Worklight Server".

From the xcode log:

[ERROR] [NONE] [https://xxxx.xxxxxxxxx.xxx.xx:444/MyPushProject/apps/services/api/MyPushApps/iphone/init] Host is not responsive.

Can someone give me some idea how to solve this issue? Thanks alot.


Solution

  • You are providing the wrong error messages. For Android you need to look at LogCat and provide the log from there. For iOS you need to look at Xcode Console and provide the log from there...You also need to mention the exact build number of Worklight 6.2 that you are using.

    For iOS, you need to make sure that you have Apple's Application Transport Security (ATS) disabled in the generated, otherwise you will not be able to connect to the server. You can see how to do this, here: https://developer.ibm.com/mobilefirstplatform/2015/09/09/ats-and-bitcode-in-ios9/

    In the generated native projects for both Android and iOS you need to look at the worklight.plist (iOS) and wlclient.properties (Android) files and ensure that the Host, Port and Context Root properties have the ones that you intended to have there, otherwise the application will attempting connecting the wrong server.