How to use a "CallBack.h" class

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

Hi

I just implemented iOS FFI and its working great.

Now need to call a javascript function that is written in kony from a iOS class in that FFI.

I tried to use CallBack.h, but I am not sure, I am using it as in correct way.

I have two functions

function A()

{

//Creates an object of class 'LaunchObjectObject'

var LaunchObjectObjectObject = new TestObjectPassing.LaunchObjectObject();

//Invokes method 'callObjectClass' on the object

LaunchObjectObjectObject.callObjectClass(/**Function*/ B);

}

function B(test)

{

frmStationInformation.lblStationName.text = test;

frmStationInformation.show();

}

the A() is used for loading a iOS native view in kony and

LaunchObjectObjectObject.callObjectClass(/**Function*/ B);

this code is used to load the native view. Along that I pass the callback method B()

Is this correct? (when passing a callback method, we have to specify only the function name like 'B' or function name with parenthesis like 'B()'? )

the B() loads a kony form

then in ios onclick action of a button i used this code

CallBack *objcallback = [[CallBack alloc] initWithCallBackObject:self.objCallback];

[objcallback executeWithArguments:[NSArray arrayWithObjects:@"", nil] spawn:true];

is it correct ?

if not please help me with the correct scenario.

Thanks

Hello,

We have already created an informational post in the Konybase camp regarding the implementation of callback functions in iOS. Please go through the below link for the same.

Link: https://basecamp.kony.com/s/question/0D56A00000AnrmVSAR/callback-function-in-ios-ffi

JS code:

function testCallBack () {

//Creates an object of class 'SharedInstance'

var SharedInstanceObject = new TestCallBack.SharedInstance();

//Invokes method 'testCallBackiOSMethod' on the object

SharedInstanceObject.testCallBackiOSMethod(

/**Function*/ callBackMethodForJs);

}

function callBackMethodForJs(array) {

kony.print('****** print ****'+ array);

}

FFI Code:

.h file

+ (id)sharedManager;

- (void)callBackMethodForJs:(CallBack*) callbackfunction;

@property (nonatomic, retain) CallBack *testCallBack;

.m file

+ (id)sharedManager {

static testCallBack *sharedMyManager = nil;

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

sharedMyManager = [[self alloc] init];

});

return sharedMyManager;

}

- (id)init {

if (self = [super init]) {

// someProperty = [[NSString alloc] initWithString:@"Default Property Value"];

}

return self;

}

- (void)callBackMethodForJs:(CallBack*) callbackfunction {

self.testCallBack = callbackfunction;

[self.testCallBack executeWithArguments:[NSArray arrayWithObjects:@"Hi", nil]];

}

Attached sample application for your reference.

Tested on:

Xcode 9.3

iPhone 7 - iOS 11.3

iOS plugins 7.3.0_r53.

Regards

Attached sample application.