2
votes

I read the following guides for native interface.

https://www.codenameone.com/how-do-i---access-native-device-functionality-invoke-native-interfaces.html

and

https://www.codenameone.com/manual/advanced-topics.html#_native_interfaces

I do the Hello World test and can't find the call for IOS to the native interface in the codename one file. I did the .h and the .m and the "generate native access". After this, I cannot check out to go on. My intension is to call a "copy from clipboard" and "paste from clipboard" native from IOS.

How do I call the native interface function hello world in codename one for IOS?

What should I import?

Is there anywhere a complete sample for IOS and native interface?

These are the files what I have now from the tutorial.

OK, the content of h file:

#import <Foundation/Foundation.h>

@interface com_mycompany_crtome_native_callsImpl : NSObject {
}

-(NSString*)helloWorld:(NSString*)param;
-(BOOL)isSupported;
@end

Then the m file:

#import "com_mycompany_crtome_native_callsImpl.h"

@implementation com_mycompany_crtome_native_callsImpl

-(NSString*)helloWorld:(NSString*)param{
    NSLog(@"MyApp: %@", param);
    return @"Tada";
}

-(BOOL)isSupported{
    return YES;
}

@end

Then I have an extra java file called native_calls.java:

package com.mycompany.crtome;

import com.codename1.system.NativeInterface;

public interface native_calls extends NativeInterface {
    String helloWorld(String hi);
}

So, I don't know how do I call that from my main java file?

And may you explain the function and the calls step by step?

1
Generate native access creates the h and m files. It's unclear where you are stuck. What's the content of your native interface? What is the problem in the native side, you normally only need to edit the m file. - Shai Almog
I added additional information, and thanks a lot for your help. It would be nice, when I could understand, what's going on, while I call a native interface. - orgen

1 Answers

1
votes

The code that binds the native interface to the iOS code is generated automatically. To use the native interface just use:

native_call n = NativeLookup.lookup(native_call.class);
if(n != null && n.isSupported()) {
   String result = n.helloWorld("Hi There");
}