For the new user I have several onboarding screens (all of them are in the same OnboardViewController). If user is successfully registered, I'd change the root controller of my app from OnboardViewController to PreLoadViewController:
let mcVC = PreLoadController()
appDelegateTemp.window?.rootViewController = mcVC
I'm using this controller to display progress of the content loading. After the content is loaded, I'm changing the root controller once again:
if let appDelegateTemp = UIApplication.shared.delegate as? AppDelegate {
let mcVC = MainViewController()
let navy = UINavigationController(rootViewController: mcVC)
appDelegateTemp.window?.rootViewController = navy
}
It works, but I have a very strange bug. When I'm trying to change settings (like, mic settings or notifications settings) from the app, I have to go to iPhone settings:
if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(settingsUrl)
}
But when I'm back I'm shown the OnboardViewController again as if appDelegate doesn't remember that current root controller is mcVC (or, rather, UINavigationController with embed mcVC).
So, why is that, and what is the right way to fix this?
Related
Is there a way to make my app default Siri app for a specified domain? For example in this article:
https://www.smashingmagazine.com/2018/04/sirikit-intents-app-guide/
The author goes to great lengths on letting the system know how the app name is to be expected, e.g. in the phrase "In List-o-Mat, show the grocery store list". But if I omit the app name in my Siri request, iOS default Reminder app seems to always take precedence.
Even if I actually delete iOS Reminder app, Siri is complaining of having no compatible app, instead of using the next logical choice.
Thank You!
No way. Default apps will open firstly if you say common words like "set alarm daily" or "call Zsolt". But you can add your app special shortcut for siri,
Firstly, you should create custom intent that can be used with Siri.
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if let _ = userActivity.interaction?.intent as? DoSomethingIntent {
if let windowScene = scene as? UIWindowScene {
self.window = UIWindow(windowScene: windowScene)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
self.window!.rootViewController = initialViewController
self.window!.makeKeyAndVisible()
initialViewController.showMessage()
}
}
}
You need to add Siri from "signing & capacity" also.
When my App opens from background by user's response to notifications, I'll direct them to the respective screen depending on the notification. The process involved replacing the window.rootViewController in AppDelegate.
The following is my codes handling the notification:
if application.applicationState == .background {
let info = userInfo["custom"] as! [AnyHashable : Any]
let a = info["a"] as! [AnyHashable : Any]
switch a["notificationType"] as! Int {
case 1:
let newVC = StoryBoardInstantiation.instantiateNewContentViewController(true)
let leftVC = StoryBoardInstantiation.instantiateLeftPanelVC()
let sideMenu = SSASideMenu(contentViewController: UINavigationController(rootViewController: newVC), leftMenuViewController: leftVC)
self.window?.rootViewController = sideMenu
}
}
Afterwards when the user navigates around the app, whenever there are animated changes to view controllers, the original ViewController(the one replaced in the codes) will be visible in the background.
How do I remove the previous rootViewController that is already replaced?
I'm using Safari Services kit to present a web view when an SCNode is clicked. However, when I go back from the safariVC to my VC with the sceneView, the sceneView is frozen even though I restart the session by re-running the session.
I read on this website that presenting another VC kills the scene view thread and I would just like confirmation. Basically I want to know whether it is possible to present another VC and be able to go back to the sceneView and "resume" the scenView
Note:
VC = ViewController
Code
How I present my safari web VC
func presentWebView(){
if let url = URL(string: "https://www.amazon.com/"){
let safariVC = SFSafariViewController(url: url)
self.present(safariVC, animated: true, completion: nil)
}
}
How I restart my session
if let worldSessionConfig = sessionConfig as? ARWorldTrackingSessionConfiguration {
worldSessionConfig.planeDetection = .horizontal
session.run(worldSessionConfig, options: [.resetTracking, .removeExistingAnchors])
}
Use sceneView.session.pause() when you present safariVC and then use sceneView.session.run to restart session when safariVC is dismissed.
I am trying to open a URL using Safari when the app gets a push notification. This works successfully when the app is in the first viewcontroller. But if the app is further into the program I get an error
<SFSafariViewController: 0x10b20ae60> on <AdViewController: 0x100b14530> whose view is not in the window hierarchy!
(AdViewController is my first view controller, so it is still focused on that one. )
I have searched this site and have tried all the suggestions for this error but have come up short. Currently, my code looks like this:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
self.window?.rootViewController?.presentedViewController?.present(safari, animated: true, completion: nil)
}
Get top most UIViewController I used extension UIApplication in Appdeleagte from the "swift 3" answer at bottom of that page and changed my code to:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
UIApplication.topViewController()?.present(safari, animated: true, completion: nil)
}
I am using deep link to open my app from browser. When my app is in background state i can able to open the app and i can able to move to the respective screen based on the URL. But whenever i quit my app, and open the same URL, it is crashing. I have followed Deep link tutorial for creating all actions. And I am moving to another screen in "triggerImp" method. I have added my code below for navigation. Is it rite or do i need to add anything else. Please help me.
let vc = UIViewController()
(appDelegate.window?.rootViewController as! UINavigationController).pushViewController(vc, animated: true)
Is this exact code that you are using? Not sure the app will know what view controller to open if you set it to UIViewController(). Here is how I have it setup that works for both states, background and inactive (using Storyboards):
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
let storyboard = UIStoryboard(name: mainEntryStoryboardName, bundle: nil)
let newHomeView = storyboard.instantiateViewControllerWithIdentifier("MyView") as! MyViewController
let navigation = MyNavigationController(rootViewController: newHomeView)
self.window!.rootViewController = navigation
return true
}
hope this helps