Salesforce

How Do I Use Native OS Code in My Mobile Application? (Magic xpa 2.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Use Native OS Code in My Mobile Application? (Magic xpa 2.x)

Sometimes you need to use native OS code in your application; for example, when using custom hardware.

The installation of Magic xpa includes samples of using native OS code. The image below shows you the Android folder where you can find the samples. There is a similar folder for iOS.

The available samples are detailed in the Mobile Native Code section in the Connectivity and Misc. Samples topic.

You can use native OS code in your application in two ways:

  1. Call from your Magic xpa application to native OS code

  2. Raise a Magic xpa user event from the native OS code

1. Call from your Magic xpa application to native OS code

This can be done by evaluating the ClientNativeCodeExecute() function with the name of the native code method and parameters.

So, for example, in the image below, the ClientNativeCodeExecute() function will execute the resize method in the ImageResize class in the mobile application code and pass it the arguments of filename, ratio, width and height.

For iOS, although you are sending several different parameters to the method, you need to define the called method with only one parameter of NSArray type. All of the Magic parameters are automatically set into this array. Then you can retrieve the parameters from the array.

The native code for this function looks as follows:

Android

The ImageResize.java file located in the Rich Internet Samples\Android\ImageResize-src folder:

iOS

The AppDelegate.mm file located in the RIAModules\iOS\Source\MagicApp folder:

2. Raise a Magic xpa user event from the native OS code

You can then raise a Magic xpa event from your code that will handled in your Magic xpa application. You do this by adding the following lines to your native code:

Android:

  1. Add the declaration: import com.magicsoftware.core.CoreApplication;

  2. Raise the event: CoreApplication.getInstance().invokeUserEvent(event_name,param1,param2); where event_name is the user event name and param1 and param2 are the values that will be passed to the user event handler.

iOS:

  1. Add the declaration: #import "Magicxpa.h"

  2. Add an array that will hold all of the parameters' values, ending with a nil value: NSArray *params = [NSArray arrayWithObjects:param1, param2, nil]; where param1 and param2 are the values that will be passed to the user event handler.

  3. Raise the event: [Magicxpa invokeUserEvent:event_name Params:params]; where event_name is the user event name.

See also

The Rich Client Samples project (programs RNC08 and RNC09)

Reference
Attachment 
Attachment