1

Now, I know that the back button in the status bar is a new feature of iOS 9, but how do I prevent that from showing the "Back to Safari" on the left of the status bar once a user has logged in from facebook ? I see other apps not having that issue, so how do I go about ensuring that that does not happen?

I can edit in any code or more information if needed. I really want to figure this out.

daredevil1234
  • 1,303
  • 1
  • 10
  • 34
  • The workaround is overlaying another view with same colour over a status bar. Please refer - http://stackoverflow.com/questions/22241412/add-uiview-banner-above-status-bar-ios-7 But I strongly encourage you not doing it. Also a possible duplicate of http://stackoverflow.com/questions/32964622/remove-back-to-safari-button-in-swift-ios-9 – ambientlight Jan 16 '16 at 19:34
  • I haven't tested it, but http://stackoverflow.com/questions/31247787/is-there-a-way-to-hide-back-to-safari-from-status-bar-in-ios9 has a solution – Michael Jan 19 '16 at 01:06

3 Answers3

1

As this reply is too long to put it in the comment textField:

I used this techniques in one of my apps.

In AppDelegate write this method for example:

    func buildUserInterface(){
    let objectID:String? = NSUserDefaults.standardUserDefaults().stringForKey("user_id")

    if objectID != nil {

        let mainStoryBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let singleMode:singleModeVC = mainStoryBoard.instantiateViewControllerWithIdentifier("singleModeVC") as! singleModeVC

        let mainPageNav = UINavigationController(rootViewController: singleMode)

        let appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        appDelegate.window?.rootViewController = mainPageNav
    }
}

It can therefore only be used, when you got a user logged in or just created.

In the ViewController handling the regristration/loggin in within the Login Block put this:

if PFUser.currentUser() != nil {

                    objectID = PFUser.currentUser()?.objectId
                    NSUserDefaults.standardUserDefaults().setObject(objectID, forKey: "user_id")




                    NSUserDefaults.standardUserDefaults().synchronize()


                    // singleModeVC
                    let mainStoryBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                    let singleMode:singleModeVC = mainStoryBoard.instantiateViewControllerWithIdentifier("singleModeVC") as! singleModeVC

                    let mainPageNav = UINavigationController(rootViewController: singleMode)

                    let appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
                    appDelegate.window?.rootViewController = mainPageNav

singleModeVC is the name and class of my view controller to appear after signing in. Hope it helps.

JVS
  • 2,592
  • 3
  • 19
  • 31
  • I'll give this a try in a bit and let you know – daredevil1234 Jan 20 '16 at 19:14
  • I didn't use NSUserDefaults since I already have a PFUser and session tokens, but setting the window to the view controller I wanted after login authenticated got the behavior I wanted – daredevil1234 Jan 21 '16 at 15:49
  • Okay, its weird, it was working but now it stopped. I didn't even change the code. – daredevil1234 Jan 21 '16 at 20:43
  • Can u try to log back in? – JVS Jan 22 '16 at 09:01
  • 1
    Hey, sorry I never selected this as the answer. It has been awhile, so I do not remember exactly what I tweaked, but it WAS working. So much of my code has changed since then, as has Swift, so I doubt this is relevant now. – daredevil1234 Jul 04 '17 at 17:01
  • @daredevil1234 it still works fine ! let me know if you still need help with this – JVS Jul 04 '17 at 17:46
0

Unfortunately, you can't. This is the default functionality in iOS 9. If you observe, the back button hides if you just go to background and come to foreground.

Varun
  • 759
  • 6
  • 12
-1

Try this:

    self.navigationItem.setHidesBackButton(true, animated: true)

Also you could try to initialize a real new viewController rather than performing a segue. I use it in some apps and it works fantastically .

JVS
  • 2,592
  • 3
  • 19
  • 31