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를 설정할 수 있다. 

https://developer.apple.com/documentation/webkit/wkwebpagepreferences/3194426-preferredcontentmode?language=objc 

 

Apple Developer Documentation

 

developer.apple.com

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

 

How to force WKWebView to show mob… | Apple Developer Forums

Assuming the website you are loading uses User-Agent to change content/layout/presentation the following will work. let config = WKWebViewConfiguration() if #available(iOS 13.0, *) { /** In iOS 13 and above WKWebViews in iPad has the ability to render desk

developer.apple.com

 

+ Recent posts