-
Notifications
You must be signed in to change notification settings - Fork 0
feat: app scenes support #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mario-launchdarkly
wants to merge
8
commits into
main
Choose a base branch
from
feature/oll1-729
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6934cf1
feat: app scenes support - unit tests
mario-launchdarkly 649730a
chore: update multi-scene example app with latests changes from sdk
mario-launchdarkly cbcd8df
fix: improve o(n*m) to o(n)
mario-launchdarkly adb5797
refactor: optimize buffer item removal using Set for improved perform…
mario-launchdarkly 6d71f7a
refactor: update cold launch handling to use process start time for i…
mario-launchdarkly 809617b
Using Secrets.config
abelonogov-ld a566891
classifier
abelonogov-ld 82b8f8e
Merge branch 'main' into feature/oll1-729
abelonogov-ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,91 @@ | ||
| // | ||
| // AppDelegate.swift | ||
| // MultiwindowPad | ||
| // | ||
| // Created by Wals, Donny on 25/10/2019. | ||
| // Copyright © 2019 Wals, Donny. All rights reserved. | ||
| // | ||
|
|
||
| import UIKit | ||
| import LaunchDarklyObservability | ||
|
|
||
| @UIApplicationMain | ||
| class AppDelegate: UIResponder, UIApplicationDelegate { | ||
| let client = Client() | ||
|
|
||
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
| LDObserve.shared.start() | ||
| return true | ||
| } | ||
|
|
||
| // MARK: UISceneSession Lifecycle | ||
|
|
||
| func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { | ||
| if let activity = options.userActivities.first, activity.activityType == "com.donnywals.viewCat" { | ||
| return UISceneConfiguration(name: "Cat Detail", sessionRole: connectingSceneSession.role) | ||
| } | ||
| return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) | ||
| } | ||
|
|
||
| func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {} | ||
| } | ||
|
|
||
| // MARK: - Scene Launch Tracking (demo) | ||
|
|
||
| return true | ||
| } | ||
| enum SceneLaunchType: String { | ||
| case cold = "Cold Launch" | ||
| case warm = "Warm Launch" | ||
| case sceneCreation = "Scene Created" | ||
|
|
||
| // MARK: UISceneSession Lifecycle | ||
| init(_ classification: SceneLaunchClassification) { | ||
| switch classification { | ||
| case .cold: self = .cold | ||
| case .warm: self = .warm | ||
| case .sceneCreation: self = .sceneCreation | ||
| } | ||
| } | ||
|
|
||
| func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { | ||
| if let activity = options.userActivities.first, activity.activityType == "com.donnywals.viewCat" { | ||
| return UISceneConfiguration(name: "Cat Detail", sessionRole: connectingSceneSession.role) | ||
| var color: UIColor { | ||
| switch self { | ||
| case .cold: return .systemBlue | ||
| case .warm: return .systemGreen | ||
| case .sceneCreation: return .systemOrange | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) | ||
| } | ||
| struct SceneLaunchEvent { | ||
| let sceneID: String | ||
| let type: SceneLaunchType | ||
| let durationMs: Double | ||
| let date: Date | ||
| } | ||
|
|
||
| func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { | ||
| // Called when the user discards a scene session. | ||
| // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. | ||
| // Use this method to release any resources that were specific to the discarded scenes, as they will not return. | ||
| } | ||
| extension Notification.Name { | ||
| static let sceneLaunchEventRecorded = Notification.Name("SceneLaunchEventRecorded") | ||
| } | ||
|
|
||
| /// Shared log that classifies scene lifecycle events into cold / warm / sceneCreation launches | ||
| /// and stores them for display. | ||
| final class SceneLaunchEventLog { | ||
| static let shared = SceneLaunchEventLog() | ||
| private init() {} | ||
|
|
||
| private(set) var events: [SceneLaunchEvent] = [] | ||
| private var classifier = SceneLaunchClassifier() | ||
|
|
||
| /// Call from `sceneWillEnterForeground` and `sceneDidBecomeActive` to record one launch event. | ||
| /// - Parameters: | ||
| /// - sceneID: The persistent session identifier of the scene. | ||
| /// - foregroundUptime: `ProcessInfo.processInfo.systemUptime` captured in `sceneWillEnterForeground`. | ||
| /// - activateUptime: `ProcessInfo.processInfo.systemUptime` captured in `sceneDidBecomeActive`. | ||
| func record(sceneID: String, foregroundUptime: TimeInterval, activateUptime: TimeInterval) { | ||
| classifier.sceneWillEnterForeground(.init(sceneID: sceneID, systemUptime: foregroundUptime)) | ||
| guard let launchInfo = classifier.sceneDidBecomeActive(.init(sceneID: sceneID, systemUptime: activateUptime)) else { | ||
| return | ||
| } | ||
|
|
||
| let durationMs = max(launchInfo.end - launchInfo.start, 0) * 1000 | ||
| let shortID = String(sceneID.prefix(8)) | ||
| let event = SceneLaunchEvent( | ||
| sceneID: shortID, | ||
| type: SceneLaunchType(launchInfo.type), | ||
| durationMs: durationMs, | ||
| date: Date() | ||
| ) | ||
| events.append(event) | ||
| NotificationCenter.default.post(name: .sceneLaunchEventRecorded, object: event) | ||
| } | ||
| } | ||
84 changes: 47 additions & 37 deletions
84
MultiSceneExampleApp/MultiwindowPad/CatSceneDelegate.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,58 @@ | ||
| // | ||
| // CatSceneDelegate.swift | ||
| // MultiwindowPad | ||
| // | ||
| // Created by Wals, Donny on 29/10/2019. | ||
| // Copyright © 2019 Wals, Donny. All rights reserved. | ||
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| class CatSceneDelegate: UIResponder, UISceneDelegate { | ||
| var window: UIWindow? | ||
|
|
||
| func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | ||
| let detail: CatDetailViewController | ||
| if let activity = connectionOptions.userActivities.first ?? session.stateRestorationActivity, | ||
| let identifier = activity.targetContentIdentifier { | ||
| detail = CatDetailViewController(catName: identifier) | ||
| } else { | ||
| detail = CatDetailViewController(catName: "default") | ||
| var window: UIWindow? | ||
|
|
||
| private var foregroundUptime: TimeInterval? | ||
|
|
||
| func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | ||
| let detail: CatDetailViewController | ||
| if let activity = connectionOptions.userActivities.first ?? session.stateRestorationActivity, | ||
| let identifier = activity.targetContentIdentifier { | ||
| detail = CatDetailViewController(catName: identifier) | ||
| } else { | ||
| detail = CatDetailViewController(catName: "default") | ||
| } | ||
|
|
||
| if let windowScene = scene as? UIWindowScene { | ||
| let window = UIWindow(windowScene: windowScene) | ||
| window.rootViewController = detail | ||
| window.backgroundColor = .white | ||
| self.window = window | ||
| window.makeKeyAndVisible() | ||
| } | ||
| } | ||
|
|
||
| if let windowScene = scene as? UIWindowScene { | ||
| let window = UIWindow(windowScene: windowScene) | ||
| window.rootViewController = detail | ||
| window.backgroundColor = .white | ||
| self.window = window | ||
| window.makeKeyAndVisible() | ||
| func sceneWillEnterForeground(_ scene: UIScene) { | ||
| foregroundUptime = ProcessInfo.processInfo.systemUptime | ||
| } | ||
| } | ||
|
|
||
| override func restoreUserActivityState(_ activity: NSUserActivity) { | ||
| super.restoreUserActivityState(activity) | ||
| print("WILL RESTORE") | ||
| } | ||
| func sceneDidBecomeActive(_ scene: UIScene) { | ||
| let activateUptime = ProcessInfo.processInfo.systemUptime | ||
| if let foregroundUptime { | ||
| SceneLaunchEventLog.shared.record( | ||
| sceneID: scene.session.persistentIdentifier, | ||
| foregroundUptime: foregroundUptime, | ||
| activateUptime: activateUptime | ||
| ) | ||
| self.foregroundUptime = nil | ||
| } | ||
| LaunchStatsOverlayView.install(in: window) | ||
| } | ||
|
|
||
| func stateRestorationActivity(for scene: UIScene) -> NSUserActivity? { | ||
| return scene.userActivity | ||
| } | ||
| override func restoreUserActivityState(_ activity: NSUserActivity) { | ||
| super.restoreUserActivityState(activity) | ||
| } | ||
|
|
||
| func sceneDidDisconnect(_ scene: UIScene) { | ||
| scene.session.stateRestorationActivity = scene.userActivity | ||
| } | ||
| func stateRestorationActivity(for scene: UIScene) -> NSUserActivity? { | ||
| return scene.userActivity | ||
| } | ||
|
|
||
| func sceneWillResignActive(_ scene: UIScene) { | ||
| scene.session.stateRestorationActivity = scene.userActivity | ||
| } | ||
| func sceneDidDisconnect(_ scene: UIScene) { | ||
| scene.session.stateRestorationActivity = scene.userActivity | ||
| } | ||
|
|
||
| func sceneWillResignActive(_ scene: UIScene) { | ||
| scene.session.stateRestorationActivity = scene.userActivity | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.