处理 IOS 设置更改的正确方法

use*_*902 5 objective-c ios swift phphotolibrary

如果用户在开始时不允许访问相册,我会弹出一个带有取消和设置可供选择的弹出窗口。如果他选择设置,它会将他带到设置页面,在那里他可以为应用程序启用相机和照片库。但是,一旦用户在设置中切换相机或照片库开关,我的应用程序就会崩溃,并显示“来自调试器的消息:由于信号 9 而终止”打印输出。下面是我的弹出窗口的代码

    @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)
}
Run Code Online (Sandbox Code Playgroud)

处理此问题的正确方法是什么,以便用户可以在切换开关后返回应用程序并开始选择照片?

小智 5

Apple 的文档说明如下:

  • 如果权限发生变化,应用程序将退出
  • 如果已注册,则调用后台任务到期处理程序
  • iOS然后杀死应用程序

至今没看到出路。