Using Native OS Code in Mobile Applications (Magic xpa 2.x)
Sometimes you need to use native OS code in your application; for example, when using custom hardware or when you need to access information from the device, such as the contacts list.
You can do this in your application by evaluating the ClientNativeCodeExecute function. Since version: 2.5
See also: The Mobile Native Code section in the Connectivity and Misc. Samples
Sometimes, you need to raise an event from the native OS code that will be handled in your Magic application.
You can raise a user event from your code by writing:
Android:
-
Add the declaration: import com.magicsoftware.core.CoreApplication;
-
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:
-
Add the declaration: #import "Magicxpa.h"
-
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.
-
Raise the event: [Magicxpa invokeUserEvent:event_name Params:params]; where event_name is the user event name.
Note:
Since version: 2.5
See also: The Rich Client Samples project (program RNC08)
Sometimes, you need to add a native control to the Magic forms. This can be done by attaching the native control to a Magic control using native code. To do this, you first need to get the reference to the Magic control.
You can get the reference to the Magic control from your code as follows:
Android:
-
Add the declaration: import com.magicsoftware.core.CoreApplication;
-
Add a variable to store the Magic control reference: View myCustomView = CoreApplication.getInstance().getControlByName(ctrlname,generation);
where ctrlname is the Magic control name and generation is the task generation (use 0 for the current task).
iOS:
-
Add the declaration: #import "Magicxpa.h"
-
Add a variable to store the Magic control reference: UIView *myCustomView = [Magicxpa getControlByName:ctrlname TaskGeneration:generation];
where ctrlname is the Magic control name and generation is the task generation (use 0 for the current task).
Since version: 2.5
See also: The Rich Client Samples project (program RNC09)
Up until version 2.5, you could:
-
Call native code by evaluating the ClientOSEnvGet function with the value of device_udf|my_string.
-
Raising only Magic xpa’s ExternalEvent by writing invokeExternalEvent(“my_string”); for Android devices or [self invokeExternalEvent:@“my_string”]; for iOS devices.
This is still supported but deprecated and no longer recommended.