Reputation: 31
I am trying to open the camera for an application of a big company(So the application supports multiple languages). Everything works fine but the buttons on the camera screen (Photo, Video, Retake, Cancel) doesn't localize even though the application is completely localized. However after I go to the iPhone settings and reallow camera access, then the camera buttons are shown in correct language. Same problem happens with the photo library. The "Cancel" button on the navigation bar is not localized. I have tried almost everything I saw online but couldn't find ant working solution.
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 }
})
}
}
Above you can see my code. Is there anyone having the same issue ? Any help will be great. Thanks!
EDIT: I still couldn't find a solid solution but if you don't run the app in debug mode it will work correctly.
Upvotes: 3
Views: 1264
Reputation: 299
I think localization of the Cancel button is a part of iOS and will translate automatically into user's language. You could access the strings through the UIKit. Take a look at this question: How to get localized Cancel, Done and etc?
"Here's a little macro I created to get the System UIKit Strings: #define UIKitLocalizedString(key) [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] localizedStringForKey:key value:@"" table:nil]
Use it like this:
UIKitLocalizedString(@"Search"); UIKitLocalizedString(@"Done"); UIKitLocalizedString(@"Cancel"); ..." (credit: Stephan Helinar)
(Apologies for horrific formatting, on mobile and in a hurry.)
Upvotes: 0