8

我正在使用 Apples Photos Framework 将 PHAssetCollections 加载到我的应用程序中。我总是得到智能收藏的英文名称。例如,我得到的是“收藏夹”而不是“收藏夹”(瑞典语)。我认为localizedTitle 属性会返回模拟器或iPhone 运行的语言。(在使用瑞典语和地区的 iPhone 上运行)。

有人遇到过这种情况么?示例代码:

NSArray *collectionsFetchResults;
NSMutableArray *localizedTitles = [[NSMutableArray alloc] init];

PHFetchResult *smartAlbums = [PHAssetCollection       fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
                                                                            subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
PHFetchResult *syncedAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
                                                                       subtype:PHAssetCollectionSubtypeAlbumSyncedAlbum options:nil];
PHFetchResult *userCollections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];

// Add each PHFetchResult to the array
collectionsFetchResults = @[smartAlbums, userCollections, syncedAlbums];

for (int i = 0; i < collectionsFetchResults.count; i ++) {

    PHFetchResult *fetchResult = collectionsFetchResults[i];

    for (int x = 0; x < fetchResult.count; x ++) {

        PHCollection *collection = fetchResult[x];
        localizedTitles[x] = collection.localizedTitle;
        NSLog(@"%@", collection.localizedTitle); //<= Always prints english names
    }
}
4

4 回答 4

5

为什么collection.localizedTitle不返回任何其他语言的原因是因为您的应用程序只有一个本地化,即English. 这绝对是一个 Apple Bug,但这里有一个按照这些步骤操作的 hack。

  1. Create related folder sv.lproj apart from en.lproj folder that you already have.
  2. Add a blank text file in the folder, then add the file into your project.
  3. Performing step 2. you are adding Swedish Language support to your Project.
  4. Run your code, it should return Title in Swedish.

Update

If you want to add more languages easily after adding the blank text, you can add like showed in other answer by selecting Project, and in Localization section add language and choose blank file again, as we don't want to localize other files.

Hope it helps, if doubt ask here.

Cheers.

于 2017-03-07T07:16:21.647 回答
2

I think you should just make sure you app support Swedish. Add the language you want to support Swedish for example add Swedish language

于 2017-03-09T08:54:32.600 回答
0

您的问题可能是您的任何提取都没有显式或隐式返回内置的收藏夹智能相册。(此外,将代码简化为仅检查一次获取的结果有助于诊断,因此您可以确定哪一个包含非本地化的“收藏夹”。)

PHAssetCollectionSubtypeSmartAlbumFavorites如果您明确需要收藏夹集合,请使用集合子类型搜索它。(它不应该是搜索常规专辑或同步专辑的结果,如果在顶级用户收藏中看到它,我会感到惊讶,因为据记载,它只返回用户创建的收藏。)

如果明确请求收藏夹智能相册返回的是非本地化版本,或者您的其他获取之一返回收藏夹智能相册并且它没有本地化,这可能是一个 Apple 错误 - 我建议告诉他们这件事

于 2017-03-06T20:27:06.703 回答
-1

ProJect -> Localizations -> "+ Chinese(simplified)"enter image description here

于 2017-09-05T10:16:45.263 回答