gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 08:32:02 25 4
gpt4 key购买 nike

如果用户一开始不允许访问相册,我会弹出一个提示,有取消和设置可供选择。如果他选择设置,则会将他带到设置页面,他可以在其中为该应用启用相机和照片库。但是,一旦用户在设置中切换相机或照片库开关,我的应用程序就会崩溃,并打印输出“来自调试器的消息:由于信号 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)
}

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

最佳答案

Apple's documentation说如下:

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

到目前为止还没有找到解决办法。

关于ios - 处理 IOS 设置更改的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39269232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com