2

Short: The Android-API for Air-Native-Extensions provides a getActivity() on the Context-Object. I am looking for a way, to get the current ViewController in iOS-Native-Extensions

Long: We need to extend Air with more than just some iOS-API-Calls to access vibration etc, but want to display a View (MPMediaPickerController to select a File from the iTunes library). In the Keynote to native extensions on Adobe MAX 2011 (http://tv.adobe.com/watch/max-2011-develop/how-to-extend-your-mobile-air-applications-using-native-extensions/) Oliver Goldman said, it is okay to show complete Views by using native extensions. To show the MPMediaPickerController (or any other View), I need to call presentModalViewController on the current ViewController or need access to the Navigation Controller. I hoped there is a way to get a pointer to the controller somehow, but I have not found any documentaion about it.

jensk
  • 41
  • 6

1 Answers1

3

You can use this piece of code. It works.

UIViewController * myViewController;
id delegate = [[UIApplication sharedApplication] delegate];
UIWindow * win = [delegate window];
myViewController = [[MyView alloc] init];
// CGRect rect = CGRectMake(x,y,w,h);
// init the view position some how  myViewController.viewFrame = rect;

[win addSubview:myViewController.view];

Hope this helps.

Best, Emil

Heitara
  • 452
  • 5
  • 10
  • Thanks a lot!! I had a UIWebView and wanted to display it, so adding it as a subview of UIView worked. The UIWebView has to be initialized with the specified rect, though – zavr Jun 18 '14 at 14:02
  • @Heitara Is it possible to override methods in the UIViewController? Especially: preferredScreenEdgesDeferringSystemGestures – Oldes May 23 '18 at 11:07
  • @Oldes yes - https://developer.apple.com/documentation/uikit/uiviewcontroller/2887512-preferredscreenedgesdeferringsys – Heitara Feb 05 '19 at 16:56