简体   繁体   English

iOS 10相机视图显示API_Cancel_Title而不是取消

[英]iOS 10 Camera view showing API_Cancel_Title instead of Cancel

I am working on an app using iOS 10 and using camera for taking pictures. 我正在使用iOS 10和使用相机拍照的应用程序。 When camera view opens, instead of cancel button there is a title "API_CANCEL_TITLE". 当相机视图打开时,而不是取消按钮,标题为“API_CANCEL_TITLE”。 And when I capture the pic the whole title is seeing, I want that instead of this long title it will be look "Cancel". 当我捕捉到整个标题看到的图片时,我想要的不是这个长标题,而是看起来“取消”。 I have used app localization. 我使用过应用本地化。 I searched few links but could not find the solution. 我搜索了几个链接但找不到解决方案。

Here is the screen shot: 这是屏幕截图:

在此输入图像描述

This is happening only in iOS 10, in iOS 9 it will working correctly here is the code: 这只发生在iOS 10中,在iOS 9中它将正常工作在这里是代码:

- (IBAction)takePicturePressed:(UIButton *)sender
{

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:nil];
}

Please suggest... 请建议......

I've approached the same problem using BundleLocalization and I've traced UIImagePickerController keys, that it gets from a bundle. 我使用BundleLocalization接近了同样的问题,并且我已经跟踪了它从一个包中获取的UIImagePickerController键。

Turns out, it uses 4 "tables" (in NSBundle nomenclature): 事实证明,它使用了4个“表”(在NSBundle命名法中):

  • CameraUI (for camera) CameraUI (用于相机)
  • PhotoLibraryServices (for PhotoLibrary) PhotoLibraryServices (适用于PhotoLibrary)
  • PhotoLibrary (for PhotoLibrary) PhotoLibrary (适用于PhotoLibrary)
  • PhotosUI (for PhotoLibrary) PhotosUI (适用于PhotoLibrary)

In my case, all I had to do, to localize UIImagePickerController interface, it was create in the project a couple of .strings files and localize them. 在我的情况下,我必须做的就是本地化UIImagePickerController接口,它在项目中创建了几个.strings文件并对它们进行了本地化。

Below content of mentioned files with keys I've seen (with standard english values), they are pretty self explaining 下面提到的文件的内容与我见过的键(标准英语值),他们是非常自我解释

CameraUI.strings CameraUI.strings
 "PHOTO" = "PHOTO"; "AEAF_LOCK_TEXT" = "AE/AF LOCK"; "API_CANCEL_TITLE" = "Cancel"; "HDR_AUTO" = "Auto"; "HDR_ON" = "On"; "HDR_OFF" = "Off"; "TIMER_OFF_TEXT" = "Off"; "USE_PHOTO" = "Use Photo"; 
PhotoLibraryServices.strings PhotoLibraryServices.strings
"CANCEL" = "Cancel";
"RETAKE" = "Retake";
"STREAM_SHARED_BY_ME_SUBTITLE" = "From You";
"STREAM_SHARED_BY_SUBTITLE" = "From %@";
"ALBUM_IMAGE_COUNT_FORMAT" = "%@ Photos";
"ALBUM_VIDEO_COUNT_FORMAT" = "%@ Videos";
"1_ALBUM_PHOTO" = "1 Photo";
"1_ALBUM_VIDEO" = "1 Video";
"ALBUM_TWO_TYPES_LABEL_COMMAS" = "%@, %@";
PhotoLibrary.strings PhotoLibrary.strings
 "CANCEL" = "Cancel"; "RETAKE" = "Retake"; "STREAM_SHARED_BY_ME_SUBTITLE" = "From You"; "STREAM_SHARED_BY_SUBTITLE" = "From %@"; "ALBUM_IMAGE_COUNT_FORMAT" = "%@ Photos"; "ALBUM_VIDEO_COUNT_FORMAT" = "%@ Videos"; "1_ALBUM_PHOTO" = "1 Photo"; "1_ALBUM_VIDEO" = "1 Video"; "ALBUM_TWO_TYPES_LABEL_COMMAS" = "%@, %@"; 
PhotosUI.strings PhotosUI.strings
 "ALL_PHOTOS_IN_LIBRARY" = "Moments"; "PXUserCollectionsSectionTitle" = "My Albums"; "FULL_PHOTOS_GRID_ZOOM_LEVEL_TITLE" = "Moments"; "NO_PHOTOS_OR_VIDEOS" = "No Photos or Videos"; "EMPTY_ALBUM_LIST_MESSAGE_iPhone" = "You can take photos and videos using camera, or sync photos and videos onto your iPhone using iTunes"; 

I have an approach, I know it will be not a perfect solution however until get a perfect one, we can use this: 我有一个方法,我知道它不是一个完美的解决方案,但是在得到一个完美的解决方案之前,我们可以使用它:

Use an custom camera view. 使用自定义相机视图。 Manage it with condition if device version is 10 or greater than 10 then execute custom camera view settings else use the default camera view. 如果设备版本为10或大于10,则使用条件进行管理,然后执行自定义摄像机视图设置,否则使用默认摄像机视图。

By using custom view, the API_Cancel_Title button hides and rest of the functionality works well. 通过使用自定义视图,API_Cancel_Title按钮隐藏,其余功能运行良好。 Here is the link that I used for a reference: Removing the cancel button from Custom camera 以下是我用作参考的链接: 从自定义相机中删除取消按钮

On this Extension of Bundle You need to check for the CameraUI in tableName. 在这个Bundle扩展您需要检查tableName中的CameraUI。 Use that change the value for the key of "Api_Cancel_title" to "Cancel" Using your own Localized value where you used to declare a your own value 使用它将“Api_Cancel_title”键的值更改为“取消”使用您自己的本地化值,用于声明您自己的值

for example 例如

English "API_CANCEL_TITLE" = "Cancel"; 英语“API_CANCEL_TITLE”=“取消”;

Hindi "API_CANCEL_TITLE" = "रद्द करना"; 印地语“API_CANCEL_TITLE”=“रद्दकरना”;

French "API_CANCEL_TITLE" = "Annuler"; 法语“API_CANCEL_TITLE”=“Annuler”;

// MARK: - Bundle Extension

extension Bundle {

    @objc func specialLocalizedStringForKey(_ key: String, value: String?, table tableName: String?) -> String {
        let currentLanguage = CSLanguage.currentAppleLanguage()
        var bundle = Bundle.main
        if let path = Bundle.main.path(forResource: currentLanguage, ofType: "lproj") {
            bundle = Bundle.init(path: path)!
        } else {
            let basePath = Bundle.main.path(forResource: "Base", ofType: "lproj")
            bundle = Bundle.init(path: basePath!)!
        }
        if let name = tableName, name == "CameraUI"{
         let values = NSLocalizedString(key, comment: name)

         return values
        }
        if let name = tableName, name == "PhotoLibrary"{
         let values = NSLocalizedString(key, comment: name)

         return values
        }
        if let name = tableName, name == "PhotoLibraryServices"{
         let values = NSLocalizedString(key, comment: name)

         return values
        }
        if let name = tableName, name == "PhotosUI"
        {
         let values = NSLocalizedString(key, comment: name)

         return values
        }
        return bundle.specialLocalizedStringForKey(key, value: value, table: tableName)
    }
}

Make sure you are not using Localization in your application, if you are using it, then properly configure all of your string files. 确保在应用程序中没有使用本地化,如果使用本地化,则正确配置所有字符串文件。

Search in your string file for API_CANCEL_TITLE and then set it to Cancel . 在您的字符串文件中搜索API_CANCEL_TITLE ,然后将其设置为“ Cancel

As the Cancel button of UIImagePickerController will change as per the localization. 因为UIImagePickerControllerCancel按钮将根据本地化而改变。

This issue come when you override localizedString function in Bundle class, that will prevent the system some time to get the reight localization values. 当您在Bundle类中覆盖localizedString函数时会出现此问题,这将阻止系统获得reight本地化值的时间。

and some developers override this function when they want to change the language of the app and show the changes immediately without closing the app, so find another way and try to not override this function 并且一些开发人员在想要更改应用程序的语言并在不关闭应用程序的情况下立即显示更改时覆盖此功能,因此找到另一种方法并尝试不覆盖此功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM