iOS 10 Camera view showing API_Cancel_Title instead of Cancel

血红的双手。 提交于 2019-12-06 01:18:52

问题


I am working on an app using iOS 10 and using camera for taking pictures. When camera view opens, instead of cancel button there is a 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:

- (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...


回答1:


I've approached the same problem using BundleLocalization and I've traced UIImagePickerController keys, that it gets from a bundle.

Turns out, it uses 4 "tables" (in NSBundle nomenclature):

  • CameraUI (for camera)
  • PhotoLibraryServices (for PhotoLibrary)
  • PhotoLibrary (for PhotoLibrary)
  • PhotosUI (for 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.

Below content of mentioned files with keys I've seen (with standard english values), they are pretty self explaining

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
"PHOTOS" = "Photos";
"CAMERA_ROLL" = "Camera roll";
"ALL_SCREENSHOTS" = "Screenshots";
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
"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";



回答2:


On this Extension of Bundle You need to check for the CameraUI in tableName. 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

for example

English "API_CANCEL_TITLE" = "Cancel";

Hindi "API_CANCEL_TITLE" = "रद्द करना";

French "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)
    }
}



回答3:


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.

By using custom view, the API_Cancel_Title button hides and rest of the functionality works well. Here is the link that I used for a reference: Removing the cancel button from Custom camera




回答4:


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.

As the Cancel button of UIImagePickerController will change as per the localization.




回答5:


This issue come when you replace localizedString function in Bundle class by another function that you create, that will prevent the system some time to get the reight localization values.

and some developers replace 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 replace this function



来源:https://stackoverflow.com/questions/40859312/ios-10-camera-view-showing-api-cancel-title-instead-of-cancel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!