How to debug Uno Classes

Hi

I’ve been trying to write a code to get phone’s native number using Foreign code, after i wrote the class the preview stopped completely so i guess there’s a problem in my class but simply i don’t know where.

So i have to ask a stupid question : How to debug uno classes ?

also do you think my class has any errors ?

using Uno;
using Uno.Collections;
using Fuse;
using Fuse.Scripting;
using Uno.Permissions;
using Uno.Threading;
using Uno.UX;

using Uno.Compiler.ExportTargetInterop;

[UXGlobalModule]
public class PhoneNumber : NativeModule
{
    static readonly PhoneNumber _instance;

    static string cachedPhoneNumber;

    public PhoneNumber(){
        if(_instance !=null) return;
        _instance = this;

        Resource.SetGlobalKey(_instance, "PhoneNumber");

        AddMember(new NativeProperty< string, object >("phoneNumber", phoneNumber));

        // async getUUID implementation
        AddMember(new NativePromise<string, string>("getLineNumber", AsyncPhoneNumber, null));
    }

    Future<string> AsyncPhoneNumber (object[] args)
    {
        return AsyncPhoneNumberImpl();
    }

    public static extern(!Android) Future<string> AsyncPhoneNumberImpl()
    {
        var p = new Promise<string>();
        p.Resolve(GetPhoneNumber());
        return p;
    }

    static extern(Android) Promise<string> _authorizePromise;

    public static extern(Android) Future<string> AsyncPhoneNumberImpl()
    {
        if (_authorizePromise == null)
        {
            _authorizePromise = new Promise<string>();
            Permissions.Request(Permissions.Android.READ_PHONE_STATE).Then(AuthorizeResolved, AuthorizeRejected);
        }
        return _authorizePromise;
    }

    private static extern(Android) void AuthorizeResolved(PlatformPermission permission)
    {
        if (cachedPhoneNumber == null) {
            cachedPhoneNumber = GetPhoneNumber();
        }
        _authorizePromise.Resolve(cachedPhoneNumber);
    }

    private static extern(Android) void AuthorizeRejected(Exception reason)
    {
        _authorizePromise.Reject(reason);
    }

    public static extern(!Android) string phoneNumber() {
        if (cachedPhoneNumber == null) {
            cachedPhoneNumber = GetPhoneNumber();
        }
        return cachedPhoneNumber;
    }

    public static extern(Android) string phoneNumber() {
        if (cachedPhoneNumber == null) {
            debug_log("Permissions not granted. Consider using Device.getUUID() instead.");
            return "";
        }
        return cachedPhoneNumber;
    }


    [Foreign(Language.Java)]
    [Require("AndroidManifest.RootElement", "<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>")]
    static extern(Android) string GetPhoneNumber()
    @{
        final android.app.Activity context = com.fuse.Activity.getRootActivity();
        android.telephony.TelephonyManager tMgr = (android.telephony.TelephonyManager)context.getSystemService(android.content.Context.TELEPHONY_SERVICE);
        String mPhoneNumber = tMgr.getLine1Number();
        return mPhoneNumber;
    @}

    static extern(!Android) string GetPhoneNumber()
    {
        debug_log("Toast not supported on this platform.");
    }
}

Thanks in advance

uno build -tandroid -d <YourProject.unoproj>, and Android Studio should start. You can debug from there. The code will look a bit different, as it’s C++ code generated from the Uno code, but it’s usually quite manageable.