gpt4 book ai didi

ios - 允许相机访问后,UIImagePickerController 不本地化?

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

我正在尝试为一家大公司的应用程序打开相机(因此该应用程序支持多种语言)。一切正常,但相机屏幕上的按钮(照片、视频、重拍、取消)没有本地化,即使应用程序已完全本地化。但是,在我进入 iPhone 设置并重新允许访问相机后,相机按钮会以正确的语言显示。照片库也会出现同样的问题。导航栏上的“取消”按钮未本地化。我已经尝试了几乎所有我在网上看到的东西,但找不到 Ant 工作的解决方案。


import Foundation
import Photos

class CameraPhotoAuthenticationManager {

static let shared = CameraPhotoAuthenticationManager()

func checkCameraAuthorization(viewController: UIViewController, picker: UIImagePickerController) {
let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
switch status {
case .authorized:
viewController.present(picker, animated: true, completion: nil)
case .notDetermined:
requestPermissionForCamera()
case .denied, .restricted:
self.showCameraNeedAccessMessage(viewController: viewController)
}
}

func checkPhotoAuthorization(viewController: UIViewController, picker: UIImagePickerController) {
if PHPhotoLibrary.authorizationStatus() == .authorized {
viewController.present(picker, animated: true, completion: nil)
} else {
PHPhotoLibrary.requestAuthorization {
status in
DispatchQueue.main.async {
if status == PHAuthorizationStatus.authorized {
viewController.present(picker, animated: true, completion: nil)
} else {
self.showNeedPhotoAccessMessage(viewController: viewController)
}
}
}
}
}

private func showNeedPhotoAccessMessage(viewController: UIViewController) {
let alertVC = UIAlertController(title: nil, message: "create.group.photo.auth".localized, preferredStyle: .alert)
alertVC.addAction(UIAlertAction(title: "create.group.alert.close".localized, style: .cancel, handler: nil))
alertVC.addAction(UIAlertAction(title: "create.group.settings".localized, style: .default, handler: { (action: UIAlertAction) -> Void in
UIApplication.shared.openURL(URL(string: UIApplication.openSettingsURLString)!)
}))
viewController.present(alertVC, animated: true, completion: nil)
}

private func showCameraNeedAccessMessage(viewController: UIViewController) {
let alertVC = UIAlertController(title: nil, message: "create.group.camera.auth".localized, preferredStyle: .alert)
alertVC.addAction(UIAlertAction(title: "create.group.alert.close".localized, style: .cancel, handler: nil))
alertVC.addAction(UIAlertAction(title: "create.group.settings".localized, style: .default, handler: {
action in
UIApplication.shared.openURL(URL(string: UIApplication.openSettingsURLString)!)
}))
viewController.present(alertVC, animated: true, completion: nil)
}

private func requestPermissionForCamera(){
AVCaptureDevice.requestAccess(for: .video, completionHandler: {accessGranted in
guard accessGranted == true else { return }
})
}


}

上面你可以看到我的代码。有没有人有同样的问题?任何帮助都会很棒。谢谢!

编辑:我仍然找不到可靠的解决方案,但如果您不在 Debug模式下运行该应用程序,它将正常工作。

最佳答案

我认为取消按钮的本地化是 iOS 的一部分,会自动翻译成用户的语言。您可以通过 UIKit 访问字符串。看看这个问题:How to get localized Cancel, Done and etc?

“这是我为获取系统 UIKit 字符串而创建的一个小宏: #define UIKitLocalizedString(key) [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] localizedStringForKey:key value:@""table:nil]

Use it like this:

UIKitLocalizedString(@"搜索"); UIKitLocalizedString(@"完成"); UIKitLocalizedString(@"取消"); ...”(来源:Stephan Helinar)

(为可怕的格式道歉,在移动设备上匆忙。)

关于ios - 允许相机访问后,UIImagePickerController 不本地化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56018763/

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