RoboVM NSNotificationCenter addObserver(), how to?

Anything libgdx related goes here!

RoboVM NSNotificationCenter addObserver(), how to?

Postby graham01 » Tue Nov 14, 2017 8:14 pm

Hi all,

I am really struggling to do some very simple things with RoboVM, it is quite uncharted territory for me and I can't seem to find much information on how to do certain things.

For now, I would just like to add a listener to the keyboard that triggers a function when it is opened, I think I am pretty close but obviously still doing it wrong, my code is as follows;

Code: Select all
public class IOSKeyboardAdapter extends NSObject {

    IOSKeyboardAdapter(IOSLauncher iosLauncher){
        Selector keyboardSelector = Selector.register("keyboardSelector");

        NSNotificationCenter.getDefaultCenter().addObserver(
                this,
                keyboardSelector,
                UIWindow.KeyboardDidShowNotification(),
                null
        );
    }

    @Callback
    @BindSelector("keyboardSelector")
    private static void keyboardSelector(NSNotification notification){
        System.out.println("keyboardSelector fired");
    }
}


This does fire on keyboard open, but crashed with;

Code: Select all
The peer object ....IOSKeyboardAdapter is not compatible with the expected type ...NSNotification


The only way I got this to not crash is to move the code to IOSLauncher and set the observer to launcher.UIWindow(), but then I get no callback in my selector, I believe the selector needs to be inside the specified observer class?

Anyway, I would greatly appreciate some help with this!

Regards,
Graham
graham01
 
Posts: 144
Joined: Thu Jul 09, 2015 4:53 am

Return to Libgdx

Who is online

Users browsing this forum: tomski, Yahoo [Bot] and 16 guests