Connecting to the MobileFirst Server
improve this page | report issueOverview
To provide the best initial experience, a MobileFirst hybrid application starts without connecting to the MobileFirst Server. It is up to the developer to decide when the application should connect to the MobileFirst Server.
As an application developer, you are responsible for maintaining the offline or online state within the application, and ensure that the application can recover from failed attempts to connect to the MobileFirst Server. This requirement also applies to native applications that use the MobileFirst SDK for connecting to the MobileFirst Server.
Connecting to the MobileFirst Server ensures that a single HTTP session between client and server communications, and thus minimizes the risk of a request race condition where a session does not exist yet and several requests are sent simultaneously from the client to the server. Hence it is recommended to establish a connection with the MobileFirst Server before any other interaction.
Connecting to the MobileFirst Server ensures that APIs that return authentication-related data such as getUserName()
or isAuthenticated()
retrieve the necessary information from the server.
API signatures
JavaScript
WL.Client.connect({
onSuccess: successCallback,
onFailure: failureCallback}
);
Objective-C
[[WLClient sharedInstance] wlConnectWithDelegate:myConnectListener];
The myConnectListener
argument is an instance of a class that conforms to the WLDelegate
protocol, with onSuccess
and onFailure
methods.
Swift
WLClient.sharedInstance().wlConnectWithDelegate(myConnectListener)
The myConnectListener
argument is an instance of a class that conforms to the WLDelegate
protocol, with onSuccess
and onFailure
methods.
Java
WLClient.createInstance(this).connect(myConnectListener);
The myConnectListener
argument is an instance of a class that implements WLResponseListener
, with onSuccess
and onFailure
methods.
C#
WLClient.getInstance().connect(myConnectListener);
The myConnectListener
argument is an instance of a class that implements WLResponseListener
, with onSuccess
and onFailure
methods.
For detailed examples of connecting to the MobileFirst Server, see the Invoking adapter procedures tutorials.
When to use the WL.Client.connect
API
It is recommended to use the WL.Client.connect
API in the following cases:
- A connection must always be initiated before the first request of any type to the MobileFirst Server. Subsequent requests must be made only after the
onSuccess
is invoked. - A new connection request is initiated after long periods of inactivity where session timeout might have occurred, such as application returning from background. Subsequent requests must be made only after the
onSuccess
is invoked.
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.