1

im redirecting the user to Settings if camera access isn't allowed and user profile page dismiss when the camera permission changed.

UIViewController dismiss after camera permission updated in Settings

  1. On tap Go to Settings option to change permission settings
  2. After Camera permission value change
  3. When on tap previous app button(?) on status bar
  4. Current UIViewController dismiss and it goes to previous UIViewController which is rootViewController

How to prevent this situation?

Sercan
  • 133
  • 13
  • 1
    Possible duplicate of [Having app restart itself when it detects change to privacy settings](https://stackoverflow.com/questions/15930708/having-app-restart-itself-when-it-detects-change-to-privacy-settings) – V D Purohit Nov 01 '18 at 12:50

2 Answers2

2

Look at that answer: Having app restart itself when it detects change to privacy settings

The app restarts and you can't prevent this. You can preserve and restore the state: https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/PreservingandRestoringState.html

messeb
  • 364
  • 2
  • 11
1

Swift 4.2

If you have a form in your app and if you might need a permission change in your app you should store&restore the data. Because your app might restart after a permission change (camera usage permission for example).

Step 1: Add Restoration IDs to your UIViewControllers from Identity Inspector on your storyboard.

Step 2: Add these methods to AppDelegate

func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
    return true
}

func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
    return true
}

Step 3: Override these methods in your UIViewController. Your data will stored in encodeRestorableState method. And they will restored in decodeRestorableState method.

override func encodeRestorableState(with coder: NSCoder) {
    coder.encode(self.myTextField.text ?? "", forKey: "myTextFieldRestorationKey")
    super.encodeRestorableState(with: coder)
}

override func decodeRestorableState(with coder: NSCoder) {
    if let txt = coder.decodeObject(forKey: "myTextFieldRestorationKey") as? String { self.myTextField.text = txt }
    super.decodeRestorableState(with: coder)
}
Sercan
  • 133
  • 13