Issue with NativeModule

this is my first attempt with implementation native module for get device id

using Uno;
using Uno.Collections;
using Fuse.Scripting;
using Fuse;
using Uno.Compiler.ExportTargetInterop;

public class UIDevice : NativeModule
{
    public UIDevice()
    {       AddMember( new NativeFunction("getDeviceID", (NativeCallback)GetDeviceID) );
    }

    object GetDeviceID(Context c, object[] args)
    {
        return getDeviceID();
    }

    [Foreign(Language.ObjC)]
    extern(iOS) public string getDeviceID () 
    @{
        NSString* Identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        return Identifier;
    @}

    [Foreign(Language.Java)]
    static extern(Android) string getDeviceID()
    @{
        TelephonyManager manager=(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String uuid = manager.getDeviceId();
        return uuid;
    @}

    static extern(!(iOS||Android)) string getDeviceID()
    {
        return "0123456789";
    }
}

… but after compilation for iOS throws me this error

plz. has anybody some idea, how can i fix it ?

Hi!

It seems that the problem is that you named your calss the same as an existing Objective-C class. Try renaming your class to something else.

such inattention … Very thanks @Anders Lassen …

I put here correct implementation of NativeModul with UIDevice detection for another people :slight_smile:

using Uno;
using Uno.Collections;
using Fuse;
using Fuse.Scripting;

using Uno.Compiler.ExportTargetInterop;

public class UserUIDevice : NativeModule
{
    public UserUIDevice()
    {       AddMember( new NativeFunction("getDeviceID", (NativeCallback)GetDeviceID) );
    }

    object GetDeviceID(Context c, object[] args)
    {
        return GetDeviceID();
    }

    [Foreign(Language.ObjC)]
    static extern(iOS) string GetDeviceID () 
    @{
        NSString* Identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        return Identifier;
    @}

    [Foreign(Language.Java)]
    static extern(Android) string GetDeviceID()
    @{
        TelephonyManager manager=(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String uuid = manager.getDeviceId();
        return uuid;
    @}

    static extern(!(iOS||Android)) string GetDeviceID()
    {
        return "0123456789";
    }
}