Swift
[Swift] WebKit 의 웹 관련 캐시 삭제 하는 방법
분명 서버에서 css나 문구를 바꾼 html을 반영 했는데 웹뷰에서는 이전 html을 불러오는 경우가 발생했다. 캐싱이 되어있어 해당 url은 캐싱 값을 가져오고 있었던 것이다.. WebKit 내 모든 캐시 데이터를 날릴 수 있는 방법이 있다. 다음 코드를 ViewWillAppear 이나 로직에 따라 사용하면 좋을 것 같다. func deleteWebCash() { let websiteDataTypes = NSSet(array: [WKWebsiteDataTypeDiskCache, // 디스크 캐시 WKWebsiteDataTypeMemoryCache, // 메모리 캐시 WKWebsiteDataTypeCookies, // 웹 쿠키, WKWebsiteDataTypeOfflineWebApplicationCach..
[Swift] Alamofire 통신에서 캐시 사용 안하는 방법
프로젝트를 진행하다가 Get 통신 부분에서 Postman에서는 서버와 일치하는 값을 잘 응답하는데 Alamofire 의 응답 값에서는 최신화 된 값을 주는 것이 아니라 캐싱 된 값을 자꾸 주는 경우가 있었다. 그때 Alamofire의 캐시처리를 하지 않는 방법이다. AF.request(url, method: .get, parameters: params, encoding: UIREncoding.default, headers: requestHeader) .cacheResponse(using: ResponseCacher.doNotCache) // 이 부분을 넣어주자 (캐시사용안함) .responseDecodatble(of: String.self) { response in ... }
[Swift] UIScrollView 내 UITextView 의 Cursor 로 focus scroll 하는 방법
UIScrollView 안에 UITextView를 넣고 textView에 포커싱을 올리면 키보드에 가려져 스크롤을 해야하는 번거로움이 있다. 그럴경우 아래와 같은 코드를 사용해보자. // UITextViewDelegate 내 override 함수에 활용 func textViewDidChange(_ textView: UITextView) { let deadlineTime = DispatchTime.now() + .milliseconds(100) DispatchQueue.main.asyncAfter(deadline: deadlineTime) { if let cursorPosition = textView.selectedTextRange?.end { let caretPositionRect = textView.c..
[Swift] ScrollView 에서 Button Highlight Delay가 생길 때
스크롤 뷰 내에 버튼 생성 시 Highlight가 딜레이가 생기는 경우가 있다. 스크롤과 버튼과의 제스처 간 충돌이기에 스크롤뷰 내 콘텐츠에 대해 딜레이를 없에고 싶으면 다음을 사용하면 된다. scrollView.delaysContentTouches = false
[Swift] CLLocationManager.locationServicesEnabled() Issue 문제
Xcode 14.0 업그레이드 후 iOS 16 기기에서 CLLocationManager.locationServicesEnabled() 사용 후 문제점 This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the -locationManagerDidChangeAuthorization: callback and checking authorizationStatus first. 해결방안 CLLocationManager.locationServicesEnabled() -> CLLocationManager.authorizationStatus 활용 lazy var locationManager:..
![[Swift] WebKit 의 WKWebView 사용법](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FbhTior%2FbtrOP5TBk6L%2FAAAAAAAAAAAAAAAAAAAAAPcOonxRFxbF0kTmy9-8oLP20qsh7O6k7m_Sh9omrbuf%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1761922799%26allow_ip%3D%26allow_referer%3D%26signature%3DuCAqJHVHrId4%252FGJ97jYMaTn33XQ%253D)
[Swift] WebKit 의 WKWebView 사용법
웹뷰 선언 // 웹뷰 선언 private var webView: WKWebView! ... override func viewDidLoad() { super.viewDidLoad() viewConfigure() ... } func viewConfigure() { // WebView let webConfiguration = WKWebViewConfiguration() let contentController = WKUserContentController() //웹 컨텍스트와 연결할 사용자 content 컨트롤러를 추가 -> "scriptHandler" 의 이름으로 주고받음 contentController.add(self, name: "scriptHandler") webConfiguration.userConte..