Resource request from native iOS Objective-C applicationsimprove this page | report issue
To create and configure an iOS native project, first follow the “Configuring a native iOS application with the MobileFirst Platform SDK” tutorial.
MobileFirst applications can access resources using the
WLResourceRequest REST API.
This tutorial explains how to use the
WLResourceRequest API with an HTTP adapter.
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.
- 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
#importwhen using the MobileFirst SDK.
- 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 signatures enable you to set parameters in the body instead of the query, or to handle the response with a delegate instead of a completion handler. See the user documentation to learn more.
If you use Xcode 7 and iOS 9, read the ATS and Bitcode blog post.
Sample and result
Click to download the MobileFirst project.
Click to download the Native project.
InvokingAdapterProceduresproject contains a MobileFirst native API which you can deploy to your MobileFirst Server instance and required to deploy to the server.
InvokingAdapterProceduresObjCproject 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.plistfile in NativeiOSInvoking with the relevant server settings.
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.