我有以下功能,显示带有两个不同选项的操作表。目前,唯一实施的选项是标题为“照片”的选项。正确呈现操作表并调用正确的操作。我的问题是,在模拟器和实际设备上,我无法显示请求访问照片库的提示。
PHPhotoLibrary.authorizationStatus()
returns .Denied
and presents the modal informing the current app does not have access to the photos:
@IBAction func attachPhotoButtonTapped(sender: AnyObject) {
let actionSheetController = UIAlertController(title: "Images", message: "Select image source...", preferredStyle: .ActionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) {
(action) in
// ...
}
actionSheetController.addAction(cancelAction)
let takePictureAction = UIAlertAction(title: "Camera", style: .Default) {
(action) in
// ...
}
actionSheetController.addAction(takePictureAction)
let choosePictureAction = UIAlertAction(title: "Photos", style: .Default) {
(action) in
PHPhotoLibrary.requestAuthorization({(status:PHAuthorizationStatus) in
switch status{
case .Authorized:
dispatch_async(dispatch_get_main_queue(), {
print("Authorized")
})
break
case .Denied:
dispatch_async(dispatch_get_main_queue(), {
print("Denied")
})
break
default:
dispatch_async(dispatch_get_main_queue(), {
print("Default")
})
break
}
})
}
actionSheetController.addAction(choosePictureAction)
presentViewController(actionSheetController, animated: true, completion: nil)
}
我已经“清理”了项目并重置了模拟器设置,但仍然没有收到显示的提示。
发生这种情况是因为CFBundleDisplayName
Info.plist 文件中的 key 值为空,并且无法构建提示访问照片库权限的警报消息。添加以下行,清理项目并再次构建可以修复问题:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>$(PRODUCT_NAME)</string>
<!-- More keys and values -->
</dict>
</plist>
谢谢弗拉基米尔·戈尔本科 https://stackoverflow.com/users/5055952/vladimir-gorbenko帮助我解决这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)