Invoking adapter procedures from native iOS applicationsTo create and configure an iOS native project, first follow the “Configuring a native iOS application with the MobileFirst Platform SDK” tutorial.
Note: The Keychain Sharing capability is mandatory while running iOS apps in the iOS Simulator when using Xcode 8. You need to enable this capability manually before building the Xcode project.
MobileFirst applications can adapt procedures to communicate with any data source. This tutorial explains how to use the REST API for returning data from an HTTP adapter. The same can be applied using other data sources (such as SQL adapters, etc).
- Access the
WLClientfunctionality by using
[WLClient sharedInstance]anywhere in your application.
- Initiate the connection to the server by using the
For most actions, you must specify a delegate object, such as a
MyConnectListenerinstance in the following example:
Note: Remember to import the
WLDelegate.hfiles in your header file and the
WLResourceRequest.hfiles in your implementation file.
- Create a delegate to be used in the
wlConnectWithDelegatemethod and receive the response from the MobileFirst Server instance. Name the class
The header file must specify that it implements the
WLDelegateprotocol specifies that the class implements the following methods:
onSuccessmethod or the
onFailuremethod of the supplied
MyConnectListenerinstance is invoked.
In both cases, the response object is sent as an argument.
- Use this object to operate data that is retrieved from the server.
Invoking an adapter procedure
After the connection is established with a MobileFirst Server instance, you can use the
WLResourceRequest class to invoke adapter procedures or call any REST resources.
- Create a
WLResourceRequestobject and choose the HTTP method (GET, POST, etc).
- Add the required parameters.
paramsparameter name to set an array of parameters.
- For Java adapters or other resources, you can use
setQueryParameterValuefor each parameter.
- Trigger the request with a call to the
Other signatures, which are not covered in this tutorial, exist for the
sendmethod. Those will enable you to set parameters in the body instead of the query, or handle the response with a delegate instead of a completion handler. See the user documentation to learn more.
Sample and result
If you use Xcode 7 and iOS 9, read the ATS and Bitcode blog post.
The sample contains two projects:
InvokingAdapterProceduresNativeProject.zip file contains a MobileFirst native API which you can deploy to your MobileFirst Server instance.
InvokingAdapterProceduresiOSProject.zip file contains a native iOS application that uses a MobileFirst native API library to communicate with the MobileFirst Server instance.
Make sure to update the
worklight.plist file in iOSNativeApp with the relevant server settings.