我通过将AccessibilityIdentifier添加到AppDelegate中包含所需信息的窗口来管理它:
int scaleFactor = [[NSNumber numberWithDouble:[UIScreen mainScreen].scale] intValue];
self.window.accessibilityIdentifier = [NSString stringWithFormat:@"windowScale:%d", scaleFactor];
稍后在我的测试中访问和解析:
var windowsScaleFactor: Int {
let scaleFactorString = self.windows.firstMatch.identifier
guard let scaleFactor = Int(scaleFactorString.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")) else {
fatalError("Could not determine window scale factor")
}
return scaleFactor
}