Thursday, July 26, 2012

Creating an External Object for the iOS generator

As Gaston explained in a previous post, one of the mechanisms for extending the model, is the use of External Objects. By creating an External Object you can provide functionality that is not provided by default by GeneXus.

The problem to be solved

Recently I needed for a project to interact with the actions of a panel, in a way that is not the default. There were basically to possibilities: to hack the solution into the GeneXus libraries, or to create an External Object to provide the functionality. We decided to use the later.

What I needed, was to be able to display the low-priority actions in a panel where the navigation bar is hidden.

Some background here. When you create a Smart Device Panel in GeneXus, you can define actions, which have a priority: High, Normal or Low. The low-priority actions are displayed in an action sheet, that is presented from a button in the navigation bar.

The problem was that the navigation bar was hidden, so the user didn't even see the button to show the action sheet.

Creating a new External Object

The implementation of an External Object consists on three parts:
  1. The implementation of the functionality, in Xcode
  2. The GeneXus object that defines the External Object's API
  3. The mapper, that translates the name of the GeneXus object to the Objective-C class.
Defining the methods in GeneXus

Lets start by creating the definition. To do that, in your GeneXus KB, create a new object of type "External Object" and give it a name. In this case, the object is called EOActions.

After that, you need to define the methods of the External Object. In this case, it has only one method named "ShowLowPriorityActions" that doesn't receive any parameters and has no return value.

Important: every method must be declared as "static" in the method properties.

Implementing the External Object

The implementation is of course in Xcode, since we need to create a library.

So, open Xcode and create a new library project.

Add a reference to the GXFlexibleClient.framework.

The main class implementing the External Object must subclass GXActionExternalObjectHandler (you'll need to add an '#import <GXFlexibleClient/GXFlexibleClient.h>' ), and it must provide two methods:
  • + (BOOL)canHandleAction:(id <GXActionExternalObjectDescriptor>)actionDesc
  • - (void)actionExecuteWithContext:(id<GXActionHandlerContext>)context delegate:(id<GXActionHandlerDelegate>)delegate
In the second one, don't forget to call [super actionExecuteWithContext:context delegate:delegate];

After that, you need to provide your custom implementation, and once you are done, you must call either one of:
  • [self onFinishedExecutingWithSuccess];
  • [self onFinishedExecutingWithError:error];
depending on the result, so the actions that are after the External Object call, can get executed.

After you compile the library, you need to copy it to the GeneXus KB. It must be placed in
  • <model_dir>\mobile\iOS\<main_obj_name>\iOS\Genexus\UserControls
so it gets copied when compiling and liked against.

Mapping the External Object name to the implementation class

The last piece, is the source file to provide the mapping between the GeneXus' object name and the class implementing it.

The class must be named GXCustomExternalObjectsMapper, and has only one method:
  • - (NSString *)externalObjectClassNameForObjectName:(NSString *)objName;
that receives the name of the object and returns the name of the class.

This sources (GXCustomExternalObjectsMapper.h and GXCustomExternalObjectsMapper.m) should be placed in
  • <model_dir>\mobile\iOS\<main_obj_name>\iOS\Genexus\Classes
Example implementation

I know this may be a little intimidating at first, but once you've done an External Object, you'll see it is not too difficult. It involves only this three steps as described above.

I've uploaded the XCode project, the GeneXus External Object export (as a .xpz file) and the mapper class to a GitHub repository, so you can play with the code.

11 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Before you start with the Mobile Application Development phase, you have to know your target audience. Determining your target audience can help you decide on what kind of application to create.

    ReplyDelete
  3. We are still in the early days of mobile phone development. Only a small fraction of the mobile phone's potential has been unlocked. Services, especially Internet access, summoners latest apk are too costly, as are the phones themselves. Smartphones try to do all things for all people but do none optimally.

    ReplyDelete
  4. With our this article we provide you a tips to watch unlimited movies and TV shows on your android and PC free of cost. You don't need to pay any single panny and don't pay for any type subscription. So we hope that this article is fullfill toram mod free your need and we will happy when your need is fullfill. If you like our this article then never forget to share it with your friends.

    ReplyDelete
  5. Here , you can find a mepco duplicate bill. If you've paid your bill but are seeking a new mepco electric bill you can look up the amount of your bill and download the mepco online bill in PDF or JPEG formats. If you'd like to verify that your bill was paid, call the mepco customer center, provide them with your reference number , and they will confirm the invoice was paid.

    ReplyDelete
  6. Why most of the start ups and entrepreneurs are outsourcing app development? It makes a lot of sense. Download & Read on to black mart apk find out why?

    ReplyDelete
  7. With a variety of so many shoes, the decision to make a perfect choice becomes daunting. This is where I can help you. To tackle the shoe-finding problem, I’ve compiled a list of 10 top-rated outdoor basketball shoes available in 2021. The features I kept in mind while compiling the list were, “durability, comfort, superior traction, and affordable budget.” If you play a lot of outdoor basketball you are probably familiar with this problem: Most basketball shoes are designed for indoor use and won’t last very long on rugged outdoor courts see this.

    ReplyDelete
  8. The expert team of the company is also dedicated to secure every shipment they handle. Pascun offer insurance protection for the items that are delicate and needs extra care. They also have different options to get the parcel delivered to the place of your choice. They have convenient pick-up and drop-off locations all over the country.

    ReplyDelete
  9. Picking the correct shoes are the utmost priority among all the clothes and accessories for tracers, because a good pair of shoes are not only important for a good performance but also for safety best hoka stability shoe. A good pair of shoes must be comfortable, have good grip and thin cushioning all while being light-weight enough to move around quickly and effortlessly. Because of these challenges very few companies make the best shoes.

    ReplyDelete
  10. iphone 13 pro max price in Pakistan are out of control, though there are ways in which a person can find Samsung mobile prices and Nokia mobile prices for cheaper than what they would pay otherwise. These different ways are something that everyone should check out in order to save themselves some money in the long run.

    ReplyDelete

  11. Creating an External Object for the iOS generator is crucial for integrating BillOnlineCheck.pk functionality seamlessly. It enhances user experience and expands the app's capabilities. Exciting times ahead for iOS developers!




    ReplyDelete