my app has 2 pages(VCs) which are created and being controlled in a BossPageViewController and I want to give the user an option of going directly to second page using a Shortcut action. now I know how to create shortcuts and how to trigger them and I also know how to open that page as root but when I open it as root I no longer can swipe to first page and also the pageDots aren't there so I should close the app and run it again to be able to swipe between pages and see pageDots.
code below is where second page shortcut triggers, I did copy and past the whole sceneDelegate here, maybe someone wants to test it:
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
var shortcutItemManager: UIApplicationShortcutItem?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let shortcutItem = connectionOptions.shortcutItem {
shortcutItemManager = shortcutItem
}
guard let _ = (scene as? UIWindowScene) else { return }
}
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
shortcutItemManager = shortcutItem
}
//MARK:- Shortcuts are Triggered here.
func sceneDidBecomeActive(_ scene: UIScene) {
if let shortcutItem = shortcutItemManager {
if shortcutItem.type == "com.x.appname.openSecondPage" {
///- tag: code lines that run secondPage as root VC
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
window.rootViewController = storyboard.instantiateViewController(withIdentifier: "SecondPageVC")
self.window = window
window.makeKeyAndVisible()
}
shortcutItemManager = nil
}
}
}
}
I also don't want to instantiate the page as popover or modal or anything else I mean just want that page as it is and not the copy of that page. code example of what I mean as copy:
let openSecondPage = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "SecondPageVC") as! SecondPageViewController
window?.rootViewController?.present(openSecondPage, animated: false, completion: nil)
I have been searching for a month but there wasn't anything exactly like this, they were similar but their code solution wasn't for me, that's why I did post this.