How to invoke WL.client.init API for MFP v8 - ibm-mobilefirst

I upgrade my cordova app to MFP v8 latest iFIx (8.0.0.00-20170220-1900) and now I am not able to connect to MFP from my cordova app.
In Xcode , I see the error
WebKit discarded an uncaught exception in the
webView:didFinishLoadForFrame: delegate: <Illigal API call> IBM
MobileFirst Platform framework is not initialized. [WL mainHtmlFilePath]
API should be used after the successful callback of the
[WL initWithDelegate:]
API. This is to ensure that IBM MobileFirst Platform framework
initialization is complete and web resources are ready to be used.
This is my snippet of the call
try {
WL.Client.init(wlInitOptions);
} catch (err) {
console.error('MFP: "WL" init error - ' + err);
initFailure(err);
}
var wlInitOptions = {
timeout: 1000,
onConnectionFailure: initFailure,
onFailure: initFailure,
onSuccess: function () {
console.log('MFP: Loaded');
initDeferred.resolve();
connectToMobileFirst();
}
};
The onSuccess or Failure method is never called.
Thanks for your help

Related

Error: Failed to complete negotiation with the server: Error: SignalR

I am using Visual Studio 2019 and implementing SignalR 5.0.0.0 in MVC project of .NET 5 framework. but unfortunately, I always get the connection error. can you please help me out? BTW it works for .net 5 with SignalR version 3.1.0.
SignalR version snippet:
SignalR conneciton script is as follows:
var connection = new signalR.HubConnectionBuilder().withUrl("/pushNotificationHub").build();
connection.on("Recive", function (notification) {
$("#modal-title").text(notification.title);
$("#modal-content").text(notification.content);
$('#myModal').modal('show');
});
connection.on("Connect", function (connectionId) {
$("#CallerConnectionId").val(connectionId);
});
connection.start().catch(function (err) {
return console.error(err.toString());
});
Below is the browser error

Unable to Register IOS device to Mobile First 8

I am able to see the iOS device under devices tab in MF, registered to my application. but pushing a notification fails with the below error:
An error occurred while the notification was sent. Internal server error. No devices found.
Upon reviewing IOS code, I noticed the below issue while invoking MFPPush.sharedInstance.registerDevice(nil)
Cannot retrieve a valid authorization header for header. Check resource and authorization server configuration.
I am using the code from the git sample. Below is the snippet throwing the error:
#IBAction func registerDevice(_ sender: AnyObject) {
print("Attempting Device registration with Mobile First")
WLAuthorizationManager.sharedInstance().obtainAccessToken(forScope: "push.mobileclient") { (token, error) -> Void in
if (error != nil) {
print("Did not recieve an access token from server: " + error.debugDescription)
} else {
WLClient.sharedInstance()?.setDeviceDisplayName("White Ipad", withCompletionHandler: { (error) in
if error == nil{
print("device display name is set")
}else{
print("error setting device name: " + error.debugDescription)
}
})
print("Recieved the following access token value: " + (token?.value ?? "no token"))
MFPPush.sharedInstance().registerDevice(nil) { (response, error) -> Void in
if error == nil {
self.enableButtons()
self.showAlert("Registered successfully with Mobile First")
print(response?.description ?? "")
} else {
self.showAlert("Registration failed with Mobile First. Error \(error?.localizedDescription)")
print(error?.localizedDescription ?? "")
}
}
}
}
}
Mobile First Config: I have followed the documentation and configured the UserLogin security check from the sample git project and have removed scope to push.mobileclient under security.
Reading the OAuth Security in MF, i understand the that token is necessary to access resources, but I am unable to figure out how to attach the token in registerDevice().
It seems to be you haven't configured Push Notifications properly in MobileFirst Server.
Make sure that you have added push.mobileclient scope in Security tab of your application. If you are not using any security check, you can add scope like below.
Check whether your application is configured valid iOS provisioning profile enabled with Push Capability
Make sure that you have uploaded valid sandbox/production certificates in Push tab of your particular app in MFP Operations Console.
More details : here
Make sure your app is enabled Push Capability in the project setting and also check you sending device token to MF Server using MFPPush.sharedInstance().sendDeviceToken(deviceToken) API in didRegisterForRemoteNotificationsWithDeviceToken method of AppDelegate file
-

OpenTok - Subscriber failed to subscribe to a stream in a reasonable amount of time

I am implementing a Network Test for my Web-application using OpenTok's js library.
To do that, I create a publisher, connect to session, then make a subscriber connect to the publisher's stream.
The Test is working on other browsers (I have tested Chrome and Internet Explorer) but on Firefox version 57.0.1 I get an error - 'The stream was unable to connect due to a network error. Make sure you have a stable network connection and that it isn't blocked by a firewall.'
Make sure when you create the OpenTok Session you are using a 'routed' Session, not a 'relayed' one. Also make sure you are passing the 'testNetwork' property to the subscribe method. Here is a working sample:
// Sample code
var session = OT.initSession(APIKEY, SESSIONID);
session.connect(TOKEN, function(err) {
if (err) {
alert(err.message);
return;
}
var publisher = session.publish();
publisher.on('streamCreated', function(event) {
session.subscribe(event.stream, null, {
testNetwork: true
}, function(err) {
if (err) alert(err.message);
});
});
});
https://jsbin.com/quruzac/edit

Preview not working properly in MFP8.0

I'm developing an application that just connects to MFP 8.0 server but when I run the app using the MFP web simulator the log says "getCachedAccessToken for scope failed: undefined" . But when I run the same application using the emulator/device it works fine.
function wlCommonInit() {
WLAuthorizationManager.obtainAccessToken().then(
function () {
alert ("You are now connected to the server");
},
function(result) {
alert("Not able to connect: "+ JSON.stringify(result));
}
);
}
Is there any way to test the MFP server connection in the MFP web simulator?
This is a known limitation of the 8.0 release.
You can read more about it, here: http://engtest01w.francelab.fr.ibm.com:9090/support/knowledgecenter/SSHS8R_8.0.0/com.ibm.worklight.dev.doc/wl_studio_tools/topics/cmbswl.html
Tokens are part of the OAuth flow.
As a workaround, you can use a simulator.

MobileFirst Platform Foundation 7.0 event listeners not working properly

I upgraded a simple hybrid Worklight project from 6.3 to 7.0. The majority of functionality is fine. However, listeners for WL.Events.WORKLIGHT_IS_CONNECTED and WL.Events.WORKLIGHT_IS_DISCONNECTED no longer function properly.
Here is the code:
function wlCommonInit(){
WL.Client.connect({onSuccess: onConnectSuccess, onFailure: onConnectFailure});
function onConnectSuccess() {
WL.Logger.debug("Connect success.");
}
function onConnectFailure() {
WL.Logger.debug("Connect failed.");
}
$("body").resize();
//Added listeners for Online/Offline functionality and set heart beat
document.addEventListener(WL.Events.WORKLIGHT_IS_CONNECTED, connectDetected, false);
document.addEventListener(WL.Events.WORKLIGHT_IS_DISCONNECTED, disconnectDetected , false);
WL.Client.setHeartBeatInterval(10);
initJson();
}
// Online/Offline Functions
function connectionFailure(){
alert("Could not connect to the MobileFirst Server.");
var output = "OFFLINE";
$('#ConnectionMsg').html(output);
}
function disconnectDetected(){
var output = "<font color='red'>DISCONNECTED</font>";
$('#ConnectionMsg').html(output);
}
function connectDetected(){
var output = "<font color='green'>CONNECTED</font>";
$('#ConnectionMsg').html(output);
if(initialConnection){
initialConnection = false;
} else {
setTimeout(function(){
//cleanDirtyDocs();
}, 20000);
}
}
Simply, the application has a footer that says "CONNECTED" or "DISCONNECTED" based on the WORKLIGHT_IS_CONNECTED and WORKLIGHT_IS_DISCONNECTED events. This works perfectly in WL6.3, but the exact same code does not work in 7.0. There is no message after initialization, just a blank footer, and the only way to get DISCONNECT to display is to call an adapter after the server is down. CONNECT is never displayed.
This makes no sense and is easy to replicate. Was there a change in how these events work? Thanks!
This is a known issue with the MFP v7.0 release. an iFix release is planned to address it. At this time there is no workaround.
Please open a PMR (support ticket) so that the fix could be delivered to you.
You can mention "APAR PI38012" for the support team to find it.