Search code examples
codenameone

Can an iOS native interface use NSData (byte[]) as a parameter or return value?


Edit: As per the answer below, the answer is YES, it can

I tried looking through the docs but didn't find any reference to this

I tried building but there always is an error whenever the return value or a param in a native interface is NSData (byte[])

Is it not supported? Thx

For example, the following interfaces blow:

- (NSData*)someMethod{
}

- (void)someMethod:(NSData*)param{
}

The server error file never mentions any specific error when an error occurs in a native interface class so I am asking here for clarity/reference


Solution

  • I'm not sure about the return value but the parameter should work and is documented in Listing 22. NativeInterface definition in the developer guide as:

    public void test(byte b, boolean boo, char c, short s,
        int i, long l, float f, double d, String ss,
        byte[] ba, boolean[] booa, char[] ca, short[] sa, int[] ia,
        long[] la, float[] fa, double[] da,
        PeerComponent cmp);
    

    Which generates:

    -(void)test:(char)param param1:(BOOL)param1
        param2:(int)param2 param3:(short)param3 param4:(int)param4
        param5:(long long)param5 param6:(float)param6
        param7:(double)param7 param8:(NSString*)param8
        param9:(NSData*)param9 param10:(NSData*)param10
        param11:(NSData*)param11 param12:(NSData*)param12
        param13:(NSData*)param13 param14:(NSData*)param14
        param15:(NSData*)param15 param16:(NSData*)param16
        param17:(void*)param17;
    }
    

    If you're getting an error we'll need the link for the full error log as well as the applicable native interface code.