The correct way to handle changes in iOS settings

If the user did not allow access to the photo album at the beginning, I offer you the "Cancel" and "Settings" pop-up menus. If he selects the settings, he will lead him to the settings page, where he will be able to turn on the camera and photo library for the application. However, as soon as the user switches the settings of the camera or photo editor, my application crashes with the imprint "Message from the debugger: terminated due to signal 9". 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 right way to handle this so that the user can return to the application and start selecting photos after switching the switch?

+4
1

Apple :

  • ,
  • ,
  • iOS

.

+4

Source: https://habr.com/ru/post/1653298/


All Articles