With 4D for iOS, we are always thinking about mobile-friendly features. The primary purpose is to help developers provide the best user experience for their mobile applications. And that’s why, with 4D v19 R3, we’re shipping action input controls.
What is an input control?
As a reminder, with formatters using iOS code available in the gallery, you can easily interact with native iOS apps from your mobile phone. For example, you can automatically dial a phone number by clicking on a phone number field or open the Safari App by simply clicking on a URL.
Action input controls follow the exact same logic. Using them, you will add some sorts of modules in your action forms to interact with Apple native apps. Several ones are already available in the gallery such as :
- phoneContact: to search for a contact phone number directly from the Apple Contact app
- emailContact: to search for a contact email directly from the Apple Contact app
- currentLocation and currentLocationAddress: to fill the current location of the app user with coordinates (latitude and longitude) and addresses automatically.
They were designed to make your users’ lives easier by opening up new perspectives through smooth interactions with the iOS environment.
And best of all, you are totally free to create your own input controls, integrate them in your mobile projects, and share them with the community!
How does this work?
To use them in your mobile projects, you’ll need to include them in your database for formatters or custom list and detail forms. To do this, create a special “inputControls” folder, download the input control that suits you best from the gallery, unzip it and drag it into the inputControls folder.
This action input control will then be available and selectable in the Action section, in the parameter properties, depending on the type of your action parameter.
Here is an example
In our example, we are going to update a contact phone number and an email. The novelty here is that we are going to get data from the Apple Contact app. So, in that case, we simply use the phoneContact and the emailContact action input controls available in the gallery.
How it looks on the user’s app
The user will just have to select the editContact action from the action menu to display the action form in the mobile app. From there, the action input controls will then give him the ability to select a phone number and an email from the Apple Contact app.
So as you can see, action input controls are another great way to interact with Apple Native apps and add nice interaction in your mobile apps.
How it looks in the project editor
Then, we need to create the edit action in the On Mobile App Action database method to get our example to work.
edit action 4D code
#DECLARE($request : Object)->$response : Object $action:=MobileAppServer.Action.new($request) $response:=New object("success"; False) Case of : ($action.name="editContact") // edit@ var $entity; $status : Object $entity:=$action.getEntity() For each ($key; $request.parameters) $entity[$key]:=$request.parameters[$key] End for each $status:=$entity.save() // save the entity If ($status.success) $response.success:=True // notify App that action success $response.dataSynchro:=True // notify App to refresh the selection $response.statusText:="Edited" Else $response.statusText:="Failed to edit" // $status.statusText $response.errors:=$status.errors End if End case
As a reminder, the MobileAppServer component, which is built in 4D, gives you access to various utility methods to speed up your 4D mobile app backend coding.