|
| 1 | +--- |
| 2 | +title: Troubleshooting |
| 3 | +sidebar_order: 5503 |
| 4 | +notSupported: |
| 5 | +description: "Troubleshoot and resolve common issues with the iOS Session Replay." |
| 6 | +--- |
| 7 | + |
| 8 | +## Session Replay is not recording with custom window setup |
| 9 | + |
| 10 | +If you have a custom window setup (e.g., multiple instances of `UIWindow`), you need to ensure that the Sentry SDK is able to find the correct window. |
| 11 | + |
| 12 | +When using window scenes, make sure that the main window is assigned in your `UIWindowSceneDelegate`'s [`window` property](https://developer.apple.com/documentation/uikit/uiwindowscenedelegate/window). |
| 13 | + |
| 14 | +```swift |
| 15 | +final class SceneDelegate: NSObject, UIWindowSceneDelegate { |
| 16 | + |
| 17 | + var window: UIWindow? |
| 18 | + |
| 19 | + func scene( |
| 20 | + _ scene: UIScene, |
| 21 | + willConnectTo session: UISceneSession, |
| 22 | + options connectionOptions: UIScene.ConnectionOptions |
| 23 | + ) { |
| 24 | + guard let scene = scene as? UIWindowScene else { return } |
| 25 | + |
| 26 | + // Configure your windows here, e.g. |
| 27 | + let mainWindow = UIWindow(windowScene: scene) |
| 28 | + mainWindow.rootViewController = UIViewController() |
| 29 | + mainWindow.makeKeyAndVisible() |
| 30 | + |
| 31 | + // Do not forget to assign the window to the SceneDelegate's window property: |
| 32 | + self.window = mainWindow |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +Alternatively, you can also create a custom proxy variable for the window: |
| 38 | + |
| 39 | +```swift |
| 40 | +final class SceneDelegate: NSObject, UIWindowSceneDelegate { |
| 41 | + |
| 42 | + var mainWindow: UIWindow? |
| 43 | + |
| 44 | + func scene( |
| 45 | + _ scene: UIScene, |
| 46 | + willConnectTo session: UISceneSession, |
| 47 | + options connectionOptions: UIScene.ConnectionOptions |
| 48 | + ) { |
| 49 | + guard let scene = scene as? UIWindowScene else { return } |
| 50 | + |
| 51 | + // Configure your windows here, e.g. |
| 52 | + let mainWindow = UIWindow(windowScene: scene) |
| 53 | + mainWindow.rootViewController = UIViewController() |
| 54 | + mainWindow.makeKeyAndVisible() |
| 55 | + |
| 56 | + // Do not forget to assign the window to the SceneDelegate's window property: |
| 57 | + self.window = mainWindow |
| 58 | + } |
| 59 | + |
| 60 | + // This is required to make sure that the Sentry SDK can find the correct window: |
| 61 | + |
| 62 | + var window: UIWindow? { |
| 63 | + get { |
| 64 | + return mainWindow |
| 65 | + } |
| 66 | + set { |
| 67 | + mainWindow = newValue |
| 68 | + } |
| 69 | + } |
| 70 | +} |
| 71 | +``` |
0 commit comments