记录一个很奇怪的问题。在 Xcode 发布包到 AppStore 后,很快就收到苹果发送的邮件,说我使用了私有 API。
环境
Apple M1
MacOS 12.2.1 (21D62)
Xcode Version 13.2.1 (13C100)
Non-public API
_UIFontFeatureSelectorIdentifierKey_ForNewSwiftAPI
_UIFontFeatureTypeIdentifierKey_ForNewSwiftAPI
代码
let fontDesc = font.fontDescriptor
if #available(iOS 15, *) {
let fractionFontDesc = fontDesc.addingAttributes(
[
UIFontDescriptor.AttributeName.featureSettings: [
[
UIFontDescriptor.FeatureKey.type: kFractionsType,
UIFontDescriptor.FeatureKey.selector: kDiagonalFractionsSelector
]
]
]
)
return UIFont(descriptor: fractionFontDesc, size: font.pointSize)
} else {
let fractionFontDesc = fontDesc.addingAttributes(
[
UIFontDescriptor.AttributeName.featureSettings: [
[
UIFontDescriptor.FeatureKey.featureIdentifier: kFractionsType,
UIFontDescriptor.FeatureKey.typeIdentifier: kDiagonalFractionsSelector
]
]
]
)
}
这段代码的作用是为了显示分数表达,比如 ½,⅓ 这样的排版。
经过揣摩上述 API 的描述,确认是 UIFontDescriptor.FeatureKey.type
和 UIFontDescriptor.FeatureKey.selector
的问题。但是官方 API 文档至今任然显示是可用的。
解决
只能继续使用 iOS15 之前的两个 API UIFontDescriptor.FeatureKey.featureIdentifier
和 UIFontDescriptor.FeatureKey.typeIdentifier
替代,经测试发现任然可以正常使用。
原因
暂时没有找到具体原因,因为这段代码之前提交是没问题的。
本文由 Bill 创作。
最后编辑时间为: 2022.02.25 at 11:28 pm