LoginSignup
6
2

More than 5 years have passed since last update.

アプリ起動時にIn-App Messagingのポップアップ位置がずれる時の対処法

Last updated at Posted at 2018-09-27

Firebaseに最近追加されたIn-App Messagingをドキュメント見ながらアプリに導入していざモーダルビューを表示させたら、何故か表示位置がずれた。

Screen Shot 2018-09-27 at 19.44.26.png

発生原因

Firebaseがポップアップを表示する時に、表示位置をAppDelegateクラスのwindowパラメータから前面のウィンドウサイズを取得して、そこから表示位置を決めているようです。

FIDRenderingWindowHelper.m

+ (UIWindow *)UIWindowForModalView {
  static UIWindow *UIWindowForModal;
  ....
  dispatch_once(&onceToken, ^{
    UIWindow *appWindow = [[[UIApplication sharedApplication] delegate] window];
    UIWindowForModal = [[UIWindow alloc] initWithFrame:[appWindow frame]];
    ....
  });
  return UIWindowForModal;
}

なので、最初に表示する画面をStoryboardのis Initial ViewControllerで設定せずUIWindowのrootViewControllerに直接セットしているようなアプリでは、UIViewControllerがセットされない限りウィンドウサイズがゼロなので、正しい位置に表示されなくなるみたいです。

対処法

空のUIViewControllerを設定したUIWindowをAppDelegateのwindowパラメータにセットしてからFirebaseApp.config()することで解決

AppDelegate.swift
 let window = UIWindow(frame: UIScreen.main.bounds)
 window.makeKeyAndVisible()
 let blankVC = UIViewController()
 window.rootViewController = blankVC
 self.window = window
 ......

 FirebaseApp.config()

結果

Screen Shot 2018-09-27 at 19.51.27.png

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2