본문 바로가기
iOS

WKWebView 대응

by _dreamgirl 2020. 12. 3.
반응형

WKWebView 대응

UIWebView는 IOS13에서 deprecated되었음
WKWebView를 12월부터 변경된 앱으로 등록해야함

 

1. 최소 Target OS
IOS 8부터 WKWebView가 도입이 되었지만 로컬 파일에 접근할 수 없는 이슈가 있음.
WKWebView를 지원하기 위해서는 IOS 9 이상이 되어야 한다.

 

2. ViewController내에서 javascript 호출 방식 차이
before

[webView stringByEvaluatingJavascriptFromString:@"window.alert('Hello World')"];


after

[webView evaluateJavaScript:@"window.alert('Hello World');" completionHandler:^{
NSLog(@"evaluate Completed");
}];

 

3.  쿠키 저장 및 관리
UIWebView는 웹뷰 사이의 모든 쿠기가 자동으로 공유
UIWebView는 NSHTTPCookieStorage로 모든 쿠키를 저장했으나

WKWebView는 각각 자신만의 쿠키 저장소를 가지기 때문에
다른 WKWebView와의 쿠키 공유가 안되고 직접 쿠키를 관리해야함
이러한 쿠키 공유를 하려면 WKProcessPool을 이용해야 한다고 함.

WKProcessPool *commonProcessPool = [[WKProcessPool alloc] init];

WKWebViewConfiguration *config1 = [[WKWebViewConfiguration alloc] init];
config1.processPool = commonProcessPool;

WKWebView *WebView1 = [[WKWebView alloc] initWithFrame : frame, configuration : config1];

WKWebViewConfiguration *config2 = [[WKWebViewConfiguration alloc] init];
config2.processPool = commonProcessPool;

WKWebView *WebView2 = [[WKWebView alloc] initWithFrame : frame, configuration : config2];

WKHTTPCookieStore 클래스를 이용하여 쿠키를 조회, 저장, 삭제 하는 방법

[WKWebsiteDataStore.defaultDataStore.httpCookieStore
	getAllCookies:^(NSArray<NSHTTPCookie *> * _Nonnull result){
    
    for(NSHTTPCookie *cookie in result){
    	
    }
]

for(NSHTTPCookie *cookie in result){
	[self.webView.configuration.websiteDataStore.httpCookieStore 
    	setCookie : cookie completionHandler : nil];
}

for(NSHTTPCookie *cookie in result){
	[self.webView.configuration.websiteDataStore.httpCookieStore 
    	deleteCookie : cookie completionHandler : nil];
}

※NSHTTPCookieStore는 더이상 쓰지 않는다.-> 하지만 기존 웹 로직의 쿠키값을 유지시키기 위해서 사용했음. 

 

4. Target SDK 9-> 11로 변경 ( iOS 11 미만에서 쿠키값 유지 해야 하는 특정 로직이 있었는데 방안이 없어서 상향으로 변경)

 

5. UIAlertView -> UIAlertController  (iOS 9 에서 first deprecated)

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"타이틀"
							message:alertMsg
                            prferredStyle:UIAlertControllerStyleAlert];
                            
UIAlerAction* ok = [UIAlertAction actionWithTitlte:@"확인"
								  style:UIAlertActionStyleDefault
                                  handler:^(UIAlertAction* action)]{
                                  
                                  [alert dismissViewControllerAnimated:YES completion:nil];
}];

[alert addAction:ok];
[self.viewController presentViewController:alert animated:YES completion:nil];

 

6. openURL 함수 변경 (iOS 10 에서 first deprecated)

[[UIApplication sharedApplication] openURL:@"url" options:@{} completionHandler:^(BOOL bSuccess){
	if(bSuccess){
    //결과  성공시 처리
    }else{
    //실패시 처리
    }
}];

[[UIApplication sharedApplication] openURL:@"url" options:@{} completionHandler:nil];

 

7. UIUserNotificationSetting (iOS 10 에서 first deprecated)

개선하고 싶지만 추후. 공부를 좀 해야 할 것 같음.

 

8. 세로 ViewController에서 가로 촬영을 위한 ViewController을 띄우면서 되돌아왔을 때
키보드 inputAccessView가 가로모드로 돌아간 경우

기존
IOS13을 대응 하면서 presnetStyle 적용했음.
기본적으로 새로운 화면을 덥는 방식
[ViewController setModalPresentationStyle:UIModalPresentationFullScreen];

새로 생성해서 뷰를 띄우지만 알파값을 통해서 이전뷰를 확인할 수 있음
[ViewController setModalPresentationStyle:UIModalPresentationOverScreen];

 

9. FACE_ID 확인 :  NSFaceIDUsageDescription pList 권한 추가

아래는 애플 공식 문서 

https://developer.apple.com/documentation/localauthentication/logging_a_user_into_your_app_with_face_id_or_touch_id

아래는 stackoverflow 질문 (2~3번째 답변 보면 됩니다.) 

https://stackoverflow.com/questions/48810153/touch-id-vs-face-id-code

 

Touch ID vs Face ID code

I wanted to ask a question about biometric authentication. In my app I entered authentication with Touch ID. Now voelvo implement the method with Face ID. I inserted the line Privacy - Face ID Usage

stackoverflow.com

 

반응형

'iOS' 카테고리의 다른 글

IOS 14 대응  (2) 2021.02.05
네트워크 속도 그리고 파일 디버깅  (0) 2021.02.01
IOS 푸시 서비스  (1) 2020.11.20
프로토콜 만들기  (0) 2020.07.05
애플님의 강경 정책  (0) 2020.04.29

댓글