TIL_20180625 ~ 20180629
25 Jun 2018 | TIL์น๋ทฐ์ฑ ๋ฏธ์ ๊ณผ WKWebKit์ ๋ํด ์ ๋ฆฌํ๊ณ ๊ณต๋ถํ ์ผ์ฃผ์ผ..์น์ ๋ชจ๋ฅด๋ ์ํ์์ WK๋ญ๊ฐ ๋ ์ง๋ณ๋ก ๋๋ ์ ์ ๋ฆฌํด์ ๋จ๊ฒจ๋์๊ฒ ์์ด์ ๊ทธ๋ฅ ์ผ์ฃผ์ผ๋์ ๊ณต๋ถํ ํ์ ์ผ๋ก TIL๋์ฒด.. :(
๋ ๋๋ง: ์์ฒญ๋ฐ์ ์ผ์ ๋ธ๋ผ์ฐ์ ํ๋ฉด์ ํ์
func webView(webView: WKWebView!, decidePolicyForNavigationAction navigationAction: WKNavigationAction!, decisionHandler: ((WKNavigationActionPolicy) -> Void)!)
- The above is a WKNavigationDelegate protocol method that gets called several times during the page load.
- One of its parameters is an WKNavigationAction object which contains information that can help you decide whether to continue page load or not.
- WKNavigationAction๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ์ฌ ์น๋ทฐ๋ฅผ ๊ณ์ ๋ก๋ํ ์ง ๋ง์ง ๊ฒฐ์ ํ๋ฉฐ, ์ด๋ฅผ ์ํด์ WKNavigationAction์ ์๋ ์์ฑ๋ค์ ์ด์ฉํ๋ค.
- request
- sourceFrame
- targetFrame
- WKNavigationActionPolicy
- .cancel
- .allow: the page loads as usual and renders in the web view
func safariViewController(SFSafariViewController, didCompleteInitialLoad: Bool) > ์ด๊ฒ ํธ์ถ๋๋ฉด ์ปดํ๋ฆฌ์ ํธ๋ค๋ฌ ํธ์ถ๋๋๋ก..?
func safariViewControllerDidFinish(SFSafariViewController) Tells the delegate that the user dismissed the view. > ์ฌํ๋ฆฌ ๋ทฐ์ปจ ๋๊ธฐ
ํ๋ฉด์ด ๋ค ๋ฐ๋๊น์ง ์๋ฐ์คํฌ๋ฆฝํธ๋ postMessage๋ฅผ ํ๋ค. load๊ฐ ํธ์ถ๋๊ณ ๋ก๋ฉ์ด ์งํ๋๋ ์ค์ navigation์ด๋ scriptmessageHandler๋ ํ์ฑํ ๋์ ๊ณ์ ๊ทธ ๋์์ด ์๋์ง ์ฐพ์ ๋ก๋ฉ์ด ์งํ๋๋ ์ค์ js๊ฐ ๊ณ์ ๋ฉ์์ง๋ฅผ postํ๋๊ฑฐ๊ฐ์ ์์ ํ ๋ก๋๋๋ฉด postMessage๋ฅผ ํ์ง ์์
์ปดํ๋ฆฌ์ ํธ๋ค๋ฌ ๋๋ฒํธ์ถ๋๋ฉด ์๋ฌ๋จ navigationType์ allow์ cancel
URL: https://m.baeminchan.com/
search failed!
URL: about:blank
search failed!
URL: https://m.baeminchan.com/search.php
search success!
2018-06-25 14:39:09.808320+0900 WebViewApp[94065:10947861] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Completion handler passed to -[WebViewApp.ViewController webView:decidePolicyForNavigationAction:decisionHandler:] was called more than once'
*** First throw call stack:
(
0 CoreFoundation 0x0000000111bd11e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x000000010d6d5031 objc_exception_throw + 48
2 CoreFoundation 0x0000000111c46975 +[NSException raise:format:] + 197
3 WebKit 0x000000011014d897 _ZNK6WebKit28CompletionHandlerCallChecker30completionHandlerHasBeenCalledEv + 203
4 WebKit 0x000000011018b462 _ZZN6WebKit15NavigationState16NavigationClient31decidePolicyForNavigationActionERNS_12WebPageProxyEON3WTF3RefIN3API16NavigationActionENS4_13DumbPtrTraitsIS7_EEEEONS5_INS_27WebFramePolicyListenerProxyENS8_ISC_EEEEPNS6_6ObjectEEN3$_1clE24WKNavigationActionPolicyP18_WKWebsitePolicies + 36
5 WebViewApp 0x000000010cdc8429 _T0SC24WKNavigationActionPolicyOIeyBy_ABIegy_TR + 25
6 WebViewApp 0x000000010cdc849d _T0SC24WKNavigationActionPolicyOIeyBy_ABIegy_TRTA + 13
7 WebViewApp 0x000000010cdc8303 _T010WebViewApp0B10ControllerC03webB0ySo05WKWebB0C_So18WKNavigationActionC15decidePolicyForySC0ghJ0Oc15decisionHandlertF + 1795
8 WebViewApp 0x000000010cdc83fc _T010WebViewApp0B10ControllerC03webB0ySo05WKWebB0C_So18WKNavigationActionC15decidePolicyForySC0ghJ0Oc15decisionHandlertFTo + 156
9 WebKit 0x000000011018886a _ZN6WebKit15NavigationState16NavigationClient31decidePolicyForNavigationActionERNS_12WebPageProxyEON3WTF3RefIN3API16NavigationActionENS4_13DumbPtrTraitsIS7_EEEEONS5_INS_27WebFramePolicyListenerProxyENS8_ISC_EEEEPNS6_6ObjectE + 752
10 WebKit 0x000000011033fec0 _ZN6WebKit12WebPageProxy31decidePolicyForNavigationActionEyRKN7WebCore18SecurityOriginDataEyONS_20NavigationActionDataERKNS_13FrameInfoDataEyRKNS1_15ResourceRequestEOSA_yRKNS_8UserDataERbRyRNS1_12PolicyActionERNS_10DownloadIDERSt8optionalINS_19WebsitePoliciesDataEE + 1286
11 WebKit 0x000000011037076a _ZN3IPC22callMemberFunctionImplIN6WebKit12WebPageProxyEMS2_FvyRKN7WebCore18SecurityOriginDataEyONS1_20NavigationActionDataERKNS1_13FrameInfoDataEyRKNS3_15ResourceRequestEOSC_yRKNS1_8UserDataERbRyRNS3_12PolicyActionERNS1_10DownloadIDERSt8optionalINS1_19WebsitePoliciesDataEEENSt3__15tupleIJyS4_yS7_S9_ySC_SC_ySG_EEEJLm0ELm1ELm2ELm3ELm4ELm5ELm6ELm7ELm8ELm9EENSW_IJbySL_SN_SR_EEEJLm0ELm1ELm2ELm3ELm4EEEEvPT_T0_OT1_RT3_NSV_16integer_sequenceImJXspT2_EEEENS16_ImJXspT4_EEEE + 139
12 WebKit 0x0000000110365da2 _ZN3IPC13handleMessageIN8Messages12WebPageProxy31DecidePolicyForNavigationActionEN6WebKit12WebPageProxyEMS5_FvyRKN7WebCore18SecurityOriginDataEyONS4_20NavigationActionDataERKNS4_13FrameInfoDataEyRKNS6_15ResourceRequestEOSF_yRKNS4_8UserDataERbRyRNS6_12PolicyActionERNS4_10DownloadIDERSt8optionalINS4_19WebsitePoliciesDataEEEEEvRNS_7DecoderERNS_7EncoderEPT0_T1_ + 322
13 WebKit 0x0000000110185d7d _ZN3IPC18MessageReceiverMap19dispatchSyncMessageERNS_10ConnectionERNS_7DecoderERNSt3__110unique_ptrINS_7EncoderENS5_14default_deleteIS7_EEEE + 141
14 WebKit 0x00000001103bc4d2 _ZN6WebKit15WebProcessProxy21didReceiveSyncMessageERN3IPC10ConnectionERNS1_7DecoderERNSt3__110unique_ptrINS1_7EncoderENS6_14default_deleteIS8_EEEE + 28
15 WebKit 0x0000000110150343 _ZN3IPC10Connection19dispatchSyncMessageERNS_7DecoderE + 209
16 WebKit 0x000000011014dcba _ZN3IPC10Connection15dispatchMessageENSt3__110unique_ptrINS_7DecoderENS1_14default_deleteIS3_EEEE + 104
17 WebKit 0x000000011015056b _ZN3IPC10Connection18dispatchOneMessageEv + 177
18 JavaScriptCore 0x000000011a9b33ac _ZN3WTF7RunLoop11performWorkEv + 236
19 JavaScriptCore 0x000000011a9b3652 _ZN3WTF7RunLoop11performWorkEPv + 34
20 CoreFoundation 0x0000000111b73bb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x0000000111b584af __CFRunLoopDoSources0 + 271
22 CoreFoundation 0x0000000111b57a6f __CFRunLoopRun + 1263
23 CoreFoundation 0x0000000111b5730b CFRunLoopRunSpecific + 635
24 GraphicsServices 0x00000001144c8a73 GSEventRunModal + 62
25 UIKit 0x000000010df71057 UIApplicationMain + 159
26 WebViewApp 0x000000010cdc9ec7 main + 55
27 libdyld.dylib 0x0000000112db2955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
์น๋ทฐ ๋ง์ง๋ง ๋ง๋ฌด๋ฆฌ ์ฑ ๋ด์์ ์น๋ทฐ๋ฅผ ์ด์ฉํ์ฌ ์น์ ๊ธฐ๋ฅ์ ์ฌ์ฉํ๊ณ , ๋์์ ์น์ ๋์์ ํต์ ํ ์๋ ์์ WKScriptMessageHandler- ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ์นํ์ด์ง๋ฅผ ์คํํ๋ฉด์ ๋ณด๋ด๋ ๋ฉ์์ง๋ฅผ ๋ฐ์์ ์ฒ๋ฆฌํ๋ ๋์์ ํ๋ ํ๋กํ ์ฝ WKUserContentController- ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ์น๋ทฐ์ ๋ฉ์์ง๋ฅผ ์ ์กํ๊ณ user script๋ฅผ ์ฝ์ ํ ์ ์๋๋ก ํจ WKNavigationDelegate- ์น์ ํ์ ๊ณผ์ ์ค ํน์ ํ ํ์ด๋ฐ์ ๋ง๋ ๋ฉ์๋๋ฅผ ํธ์ถ์ํด. ์ด์ ๋ง์ถฐ์ ์ ์ ํ custom๋์์ ๊ตฌํํ ์ ์๋ค. SFSafariViewController- ์ฑ ๋ด์์ ์น์ ์ฌํ๋ฆฌ๋ทฐ์ปจํธ๋กค๋ฌ๋ก ๋์ฐ๊ณ ๊ด๋ฆฌํ๊ฒ ํ ์ ์์ผ๋ฉฐ, ์ฌํ๋ฆฌ์ ๊ธฐ๋ฅ์ ํฌํจํ๊ณ ์๋ค.
์ฐธ๊ณ ํ๋ ๋งํฌ๋ค : https://www.appcoda.com/webkit-framework-tutorial/
Comments