Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to handle change in settings for IOS

If the user did not allow access to photo album at the start, I will prompt with a pop up with Cancel and Settings to choose from. If he chooses settings, it will bring him to settings page where he can enable camera and photo Library for the app. However, as soon as the user toggles the camera or photo library switch in settings, my app crashes with "Message from debugger: Terminated due to signal 9" printout. Below is the code for my popup

    @IBAction func cameraBarBtnPress(sender: AnyObject) {

    let photoAuthStatus = PHPhotoLibrary.authorizationStatus()

    switch photoAuthStatus {

    case .Authorized:
        presentFusumaCameraVC()

    case .Denied, .Restricted :

        showNeedPhotoAlbumAccessPopup()

    case .NotDetermined:
        PHPhotoLibrary.requestAuthorization({ (authStatus: PHAuthorizationStatus) in
            switch authStatus {
            case .Authorized:
                self.presentFusumaCameraVC()

            case .Denied, .Restricted :
                self.showNeedPhotoAlbumAccessPopup()

            case .NotDetermined:
                print("Shouldnt get to here")
            }
        })
    }
}

func showNeedPhotoAlbumAccessPopup() {
    let alertController = UIAlertController(title: "Enable Photo Album Access", message: "", preferredStyle: .Alert)
    let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)
    let settingsAction = UIAlertAction(title: "Settings", style: .Default, handler: { (action: UIAlertAction) in
        let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
        if let url = settingsUrl {
            UIApplication.sharedApplication().openURL(url)
        }
    })
    alertController.addAction(settingsAction)
    alertController.addAction(cancelAction)
    self.presentViewController(alertController, animated: true, completion: nil)
}

What would be the correct way to handle this so that the user can go back to the app and begin selecting the photos after toggling the switch?

like image 1000
user172902 Avatar asked Sep 01 '16 10:09

user172902


People also ask

How do I manage iPhone settings?

In the Settings app , you can search for iPhone settings you want to change, such as your passcode, notification sounds, and more. Tap Settings on the Home Screen (or in the App Library). Swipe down to reveal the search field, tap the search field, enter a term—“volume,” for example—then tap a setting.

How do you update iOS settings on iPhone?

Update iPhone automatically If you didn't turn on automatic updates when you first set up your iPhone, do the following: Go to Settings > General > Software Update > Automatic Updates. Turn on Download iOS Updates and Install iOS Updates.


1 Answers

Apple's documentation says the following:

  • If permissions changes, app is quit
  • Background task expiration handler is called, if registered
  • iOS then kills the application

Haven't seen a way around so far.

like image 138
Lucy.W Avatar answered Sep 30 '22 10:09

Lucy.W