Skip to content

Use displayScale instead of UIScreen.main - #112

Merged
bryankeller merged 1 commit into
masterfrom
bk/adopt-display-scale-api
Aug 22, 2022
Merged

bryankeller merged 1 commit into
masterfrom
bk/adopt-display-scale-api

Conversation

@bryankeller

Copy link
Copy Markdown
Contributor

Details

UIScreen.main is being deprecated in iOS 16. We should be able to just use the trait collection's displayScale property. All seems to work correctly in my testing.

Related Issue

N/A

Motivation and Context

Adopting latest APIs.

How Has This Been Tested

Example app.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@bryankeller bryankeller added the enhancement New feature or request label Aug 22, 2022
@bryankeller
bryankeller merged commit 35a5a35 into master Aug 22, 2022
pblazej added a commit to webrtc-sdk/webrtc that referenced this pull request May 11, 2026
Drop `[UIScreen mainScreen] / [NSScreen mainScreen]` from
`currentScaleFactor`.

Still requires some testing, especially in multiscreen scenarios.

### References

-
[livekit/client-sdk-swift#998](livekit/client-sdk-swift#998)
— App Store rejection on iOS 26 citing deprecated UIKit APIs in
`LiveKitWebRTC.framework`.
- [Apple Developer Forums — `UITraitCollection.displayScale` is the
preferred replacement](https://developer.apple.com/forums/thread/733516)
(Apple Frameworks Engineer).
- [Apple —
`UITraitCollection.displayScale`](https://developer.apple.com/documentation/uikit/uitraitcollection/1623519-displayscale)
- [Apple Metal Best Practices: Native Screen
Scale](https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/MTLBestPracticesGuide/NativeScreenScale.html)
— future TODO to switch to `nativeScale` for drawable sizing.

Prior art in other SDKs:

-
[airbnb/MagazineLayout#112](airbnb/MagazineLayout#112)
— replaced `UIScreen.main` with `traitCollection.displayScale` directly.
-
[jellyfin/Swiftfin#1809](jellyfin/Swiftfin#1809)
— same migration.
-
[flutter/flutter#162785](flutter/flutter#162785)
— chose `view.window.windowScene.screen.scale`, [reverted in
#166080](flutter/flutter#166080) after a
downstream `scale == 0` crash (informed the `MAX(scale, 1.0)` safety net
here).
-
[react-native-community#493](react-native-community/discussions-and-proposals#493)
— community discussion of the same migration.

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
cloudwebrtc pushed a commit to webrtc-sdk/webrtc that referenced this pull request Jul 16, 2026
Drop `[UIScreen mainScreen] / [NSScreen mainScreen]` from
`currentScaleFactor`.

Still requires some testing, especially in multiscreen scenarios.

### References

-
[livekit/client-sdk-swift#998](livekit/client-sdk-swift#998)
— App Store rejection on iOS 26 citing deprecated UIKit APIs in
`LiveKitWebRTC.framework`.
- [Apple Developer Forums — `UITraitCollection.displayScale` is the
preferred replacement](https://developer.apple.com/forums/thread/733516)
(Apple Frameworks Engineer).
- [Apple —
`UITraitCollection.displayScale`](https://developer.apple.com/documentation/uikit/uitraitcollection/1623519-displayscale)
- [Apple Metal Best Practices: Native Screen
Scale](https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/MTLBestPracticesGuide/NativeScreenScale.html)
— future TODO to switch to `nativeScale` for drawable sizing.

Prior art in other SDKs:

-
[airbnb/MagazineLayout#112](airbnb/MagazineLayout#112)
— replaced `UIScreen.main` with `traitCollection.displayScale` directly.
-
[jellyfin/Swiftfin#1809](jellyfin/Swiftfin#1809)
— same migration.
-
[flutter/flutter#162785](flutter/flutter#162785)
— chose `view.window.windowScene.screen.scale`, [reverted in
#166080](flutter/flutter#166080) after a
downstream `scale == 0` crash (informed the `MAX(scale, 1.0)` safety net
here).
-
[react-native-community#493](react-native-community/discussions-and-proposals#493)
— community discussion of the same migration.

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants