编辑操作标题的 UIActivityViewController 问题 - SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE

UIActivityViewController issue with the Edit Actions title - SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE

我遇到了与标题为 编辑操作UIActivityViewController 相关的问题。

它显示 SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE 而不是 Edit Actions..

调查结果:

  1. 在 WhatsApp 和 Instagram 等其他应用程序中工作正常。
  2. 相同的代码在新创建的 iOS 应用程序中运行良好。
  3. 在 iOS 15.0 和 iOS 14.0+ 中使用 Xcode 版本 13.1 进行了测试。
  4. 已在设备和模拟器上进行测试。

备注:

该项目使用 ObjectiveC 并创建于 3 年之前。

代码:

NSString* shareText = @"Sharing an eddress with you";
NSURL *website = [NSURL URLWithString:@"http://eddress.co/EDDRSS"];
NSArray *shareArray = @[shareText, website];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:shareArray applicationActivities:nil];
[activityVC setValue:@"Someone shared an eddress with you" forKey:@"subject"];
NSArray *excludeActivities = @[UIActivityTypeAirDrop,
                                   UIActivityTypePrint,
                                   UIActivityTypeAssignToContact,
                                   UIActivityTypeSaveToCameraRoll,
                                   UIActivityTypeAddToReadingList,
                                   UIActivityTypePostToFlickr,
                                   UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];

截图:

非常感谢对此的任何帮助。

终于找到了根本原因和解决方法。一切都是由于本地化

下面的代码才是真正的罪魁祸首

#pragma mark - Method Swizzling
- (NSString *)customLocaLizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName {
    NSBundle*bundle = [BundleLocalization sharedInstance].localizationBundle;
    return [bundle customLocaLizedStringForKey:key value:value table:tableName];
}

这个returnsSHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE而不是Edit Actions..

看下面的日志

key:SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE value: tableName:Localizable
return: SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE
key:SHARE_SHEET_EDIT_SECTION_TITLE_FAVORITES value: tableName:Localizable
return: SHARE_SHEET_EDIT_SECTION_TITLE_FAVORITES
key:SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE value: tableName:Localizable
return: SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE
key:Copy[Activity] value:Copy tableName:Localizable
return: Copy
key:SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE value: tableName:Localizable
return: SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE
key:SHARE_SHEET_DEFAULTS_REMOVE_BUTTON_TITLE value: tableName:Localizable
return: SHARE_SHEET_DEFAULTS_REMOVE_BUTTON_TITLE
key:Copy[Activity] value:Copy tableName:Localizable
return: Copy
key:SHARE_SHEET_EDIT_SECTION_TITLE_OTHER value: tableName:Localizable
return: SHARE_SHEET_EDIT_SECTION_TITLE_OTHER
key:SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE value: tableName:Localizable
return: SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE

临时解决方案:

#pragma mark - Method Swizzling

- (NSString *)customLocaLizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName {
    if ([key isEqualToString:@"SHARE_SHEET_EDIT_ACTIONS_BUTTON_TITLE"]) {
        return @"Edit Actions...";
    }
    else if ([key isEqualToString:@"SHARE_SHEET_EDIT_SECTION_TITLE_FAVORITES"]) {
        return @"Favorites";
    }
    else if ([key isEqualToString:@"SHARE_SHEET_EDIT_SECTION_TITLE_OTHER"]) {
        return @"Other Actions";
    }
    else if ([key isEqualToString:@"SHARE_SHEET_EDIT_SECTION_TITLE_SUGGESTIONS"]) {
        return @"Suggestions";
    }
    else if ([key isEqualToString:@"SHARE_SHEET_DEFAULTS_REMOVE_BUTTON_TITLE"]) {
        return @"Remove";
    }
    else {
        NSBundle *bundle = [BundleLocalization sharedInstance].localizationBundle;
        return [bundle customLocaLizedStringForKey:key value:value table:tableName];
    }
}