1

Is there a way to access the UIViewController, the stage is running on? AFAIK there is something like that in RoboVM and on Android we have the FXActivity fur such tasks...

Thanks and regards, Daniel

dzim
  • 1,131
  • 2
  • 12
  • 28

1 Answers1

1

If you have a look at the Charm Down plugins, some of them require native implementation on iOS, and in a few cases they also require access to the UIViewController.

For instance, the Picture plugin iOS implementation requires access to the UIImagePickerController, to create a subview that is added on top of the current view.

For that, you declare an interface:

@interface Pictures : UIViewController <...> {}

and later on you implement the access to that controller:

NSArray *views = [[[UIApplication sharedApplication] keyWindow] subviews];
UIView *_currentView = views[0];

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

[_currentView.window addSubview:picker.view];

Notice that the iOS native code has to be compiled and added as a native library.

Check the task xcodebuild here. You will have to use it in your build.gradle file to build the native library, then copy it to your project under src/ios/jniLibs. See this question for a custom use case of it.

Community
  • 1
  • 1
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • Hi José. Thank you - again :-) - for the information. Will try that and accept the answer later, ok? – dzim Feb 08 '17 at 13:28
  • Sure, no problem. It takes a while to make it work... Just fork Charm Down and start from there, or just select one of the plugins, like Pictures. – José Pereda Feb 08 '17 at 13:30
  • I guess it's alright. A colleague of mine - who actually __can__ program Objective-C/Swift - looked into it and came up with a pure Java code version for the audio player and video (via some kind of preview API, that's also exposed in RoboVM). – dzim Feb 10 '17 at 12:17
  • It would be nice having a Java version, but probably it will be easier having JavaFX media ported? – José Pereda Feb 10 '17 at 12:22
  • I guess having the __MediaPlayer__ ported would be the __ideal solution in any case__! Nevertheless: Using the `RoboVM` Java code is nice, but since the API will either be replaced with `MobiDevelop`'s version (more up to date, I guess) or the `GluonVM` (am I right?), then this work might need to be done _again_ at some point... Are you interested in the code? – dzim Feb 10 '17 at 12:26
  • Sure, I can have a look. In any case, we had before the RoboVM API working on top of the Charm Down iOS implementation, but basically it was a wrapper of the native code, which is what we do now directly, without further dependencies. – José Pereda Feb 10 '17 at 12:29
  • Ok. But: Where should I post it? I don't want to pollute this question... (Maybe a Gist on Github?) And by the way: there is a new question incoming (sorry, but I probably found another smaller issue with javafxports)... – dzim Feb 10 '17 at 12:33
  • If you can share the link, post it in this comments, or if you think it is relevant, add it as a possible answer to this [question](http://stackoverflow.com/questions/40719095/embed-native-video-view-in-gluon-app/41202608#41202608)? – José Pereda Feb 10 '17 at 12:35
  • Video: http://stackoverflow.com/questions/40719095/embed-native-video-view-in-gluon-app/42160114#42160114 Audio: http://stackoverflow.com/questions/38419634/javafxports-how-to-call-android-native-media-player/42160145#42160145 and finally my new question: http://stackoverflow.com/questions/42160169/javafxports-battery-consumtion-screen-always-on :-D – dzim Feb 10 '17 at 13:07
  • 1
    Ok, thanks. As I said before, Charm Down followed that approach a while ago using RoboVM API. Now it directly provides API and the native implementation, so you don't depend on third parties and it can be freely extended when required. – José Pereda Feb 10 '17 at 13:15