Skip to content

Commit 47170af

Browse files
Fix getting rootViewController on iOS (#138)
Fix getting the rootViewController on iOS in complex situations.
1 parent 87604e8 commit 47170af

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/firebase-admob/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ export const topViewController = (): UIViewController | undefined => {
6868
};
6969

7070
const rootViewController = (): UIViewController | undefined => {
71-
const keyWindow = UIApplication.sharedApplication.keyWindow;
72-
return keyWindow != null ? keyWindow.rootViewController : undefined;
71+
const app = UIApplication.sharedApplication;
72+
const window = app.keyWindow || (app.windows.count > 0 && app.windows[0]);
73+
return window != null ? window.rootViewController : undefined;
7374
};
7475

7576
const findTopViewController = (root: UIViewController): UIViewController | undefined => {

0 commit comments

Comments
 (0)