728x90
if #available(iOS 13.0, *) {
/**
In iOS 13 and above WKWebViews in iPad has the ability to render desktop versions of web pages.
One of the properties they change to support this is the User-Agent.
Therefore forcing the WKWebView to load the mobile version.
*/
let pref = WKWebpagePreferences.init()
pref.preferredContentMode = .mobile
config.defaultWebpagePreferences = pref
}
위와 같이 iOS13에서는 WKWebpagePreferences의 속성에 preferredContentMode를 설정할 수 있다.
preferredContentMode는 enum상수로 3가지 옵션이 정의되어있다 (2022.4.6 기준)
extension WKWebpagePreferences {
/** @enum WKContentMode
@abstract A content mode represents the type of content to load, as well as
additional layout and rendering adaptations that are applied as a result of
loading the content
@constant WKContentModeRecommended The recommended content mode for the current platform
@constant WKContentModeMobile Represents content targeting mobile browsers
@constant WKContentModeDesktop Represents content targeting desktop browsers
@discussion WKContentModeRecommended behaves like WKContentModeMobile on iPhone and iPad mini
and WKContentModeDesktop on other iPad models as well as Mac.
*/
@available(iOS 13.0, *)
public enum ContentMode : Int, @unchecked Sendable {
case recommended = 0
case mobile = 1
case desktop = 2
}
}
웹뷰 초기화시 정의한 config를 넘기면 된다.
WKWebView(frame: rect, configuration: config)
참고
https://developer.apple.com/forums/thread/674232
'Mobile App Develop > iOS개발' 카테고리의 다른 글
This operation can fail if the version of the OS on the device is incompatible with the installed version of Xcode. 오류 뜰 시 (0) | 2022.07.05 |
---|---|
[iOS개발] 리액트네이티브 웹뷰 - pod install 안될때 (0) | 2022.06.21 |
[Xcode] iOS 앱 스키마 등록 (0) | 2022.02.08 |
[Xcode] iOS 앱 기본 언어(Localization) 설정 (0) | 2022.02.04 |
[Xcode] iOS 사진 찍기 시 앱 크래시 오류 수정 (Privacy설정) (0) | 2022.02.03 |