diff --git a/packages/core/utils/native-helper.d.ts b/packages/core/utils/native-helper.d.ts index 8fed91420..e21f9f131 100644 --- a/packages/core/utils/native-helper.d.ts +++ b/packages/core/utils/native-helper.d.ts @@ -132,6 +132,11 @@ export namespace iOSNativeHelper { export function nsArrayToJSArray(a: NSArray): T[]; } + /** + * Get the root UIViewController of the app + */ + export function getRootViewController(): any; /* UIViewController */ + /** * Data serialize and deserialize helpers */ diff --git a/packages/core/utils/native-helper.ios.ts b/packages/core/utils/native-helper.ios.ts index d01d85532..b6d70fc87 100644 --- a/packages/core/utils/native-helper.ios.ts +++ b/packages/core/utils/native-helper.ios.ts @@ -136,6 +136,16 @@ export namespace iOSNativeHelper { } } + export function getRootViewController(): UIViewController { + const app = UIApplication.sharedApplication; + const win = app.keyWindow || (app.windows && app.windows.count > 0 && app.windows.objectAtIndex(0)); + let vc = win.rootViewController; + while (vc && vc.presentedViewController) { + vc = vc.presentedViewController; + } + return vc; + } + export function isLandscape(): boolean { console.log('utils.ios.isLandscape() is deprecated; use application.orientation instead');