【发布时间】:2017-01-09 04:51:31
【问题描述】:
如果用户在开始时不允许访问相册,我将弹出“取消”和“设置”提示以供选择。如果他选择设置,它会将他带到设置页面,他可以在其中为应用程序启用相机和照片库。但是,一旦用户在设置中切换相机或照片库开关,我的应用程序就会崩溃,并显示“来自调试器的消息:由于信号 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)
}
处理此问题的正确方法是什么,以便用户在切换开关后可以返回应用程序并开始选择照片?
【问题讨论】:
-
你的 PHPhotolibrary.authorizationStatus() 方法的实现是什么?
-
我没有实现 PHPhotolibrary。授权状态()我自己。它来自苹果的 PHPPhotoLibrary: NSObject 类
-
photoAuthStatus 的值是多少?
-
在我的手机获得照片访问权限的那一刻,photoAuthStatus.rawValue 和 photoAuthStatus.hasValue 的值为 3。你在想什么?
-
在我看来 Instagram 也被杀死了。
标签: ios objective-c swift phphotolibrary