영리치
나의 재물운? 연애운은?
AI가 봐주는 내 사주팔자 - 운세박사
const pushDeeplink = (e: any) => { if (!e.data.startsWith('ExponentPushToken') && e.data.includes('://')) { route.replace(e.data); alert(e.data); if (e.data === 'https://yonsang.net/chat' && route.pathname.includes('/chat')) { window.location.reload(); } } }; useEffect(() => { const userAgent = window.navigator.userAgent; if (userAgent === 'isWebViewAOS') { document.addEventListener('message', (e: any) => pushDeeplink(e)); } else if (userAgent === 'isWebViewIOS') { window.addEventListener('message', (e: any) => pushDeeplink(e)); } return () => { document.removeEventListener('message', (e: any) => pushDeeplink(e)); window.removeEventListener('message', (e: any) => pushDeeplink(e)); }; }, []);
웹
const onLoadEnd = () => { webRef.current.postMessage(pushUrl); };
앱
const onLoadProgress = () => { webRef.current.injectJavaScript( `window.ReactNativeWebView.postMessage(window.location.href)` ); };
앱 (웹 -> 앱)
저 onLoadProgress가 injectJavaScript로 원격으로 웹에서 코드를 실행해주는데
window.ReactNativeWebView.postMessage() 이 코드를 실행시키거든요
그말인 즉슨 웹에서도 저 코드를 실행하면 앱단으로 메세지를 보낼 수 있는거에요
고로 위에 두개가 앱에서 웹으로 보낼때, 맨 아래가 웹에서 앱으로 보낼때에요
window.ReactNativeWebView.postMessage(window.location.href)
위에는 SNS 로그인 시 토큰을 등록하는 부분.
SNS 로그인 콜백 URL에 해당 코드 삽입
나의 재물운? 연애운은?
AI가 봐주는 내 사주팔자 - 운세박사