[알게된 것] React Native WebView Pass 인증

Chobby·2023년 10월 6일
1

알게된 것

목록 보기
9/62
post-thumbnail

😀문제상황

안드로이드 앱에서 WebView를 통한 나이스 인증절차를 겪는 중 Pass 인증하기를 누르면 스토어가 열리고 정상적인 인증이 진행되지 않음

😁해결방법

AndroidManifest.xml

<permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<queries>
  <intent>
    <action android:name="android.intent.action.MAIN" />
  </intent>
</queries>

<application ...>
  <activity>
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
  </activity>
</application>

다음 구문들 추가 및

const onShouldStartLoadWithRequest = (event: any) => {
    if (
      event.url.startsWith('http://') ||
      event.url.startsWith('https://') ||
      event.url.startsWith('about:blank')
    ) {
      return true;
    }
    if (Platform.OS === 'android') {
      console.log('안드로이드');

      // 중요. openChromeIntent
      SendIntentAndroid.openChromeIntent(event.url)
        .then(isOpened => {
          if (!isOpened) {
            Alert.alert('앱 실행에 실패했습니다');
          }
        })
        .catch(err => {
          console.log(err);
        });
      return false;
    }
  };

<WebView
	...
    originWhitelist={['*']}
    onShouldStartLoadWithRequest={event => onShouldStartLoadWithRequest(event);}
    ...
/>

😂여담

다른 블로그에서 nodemodulesRNSendIntentModule.java파일을 수정하라는 글을 봤었다.

모듈을 수정한다는 것은 굉장히 귀찮은 작업들이 동반되기에 끝까지 다른 방법을 찾아보았음

Chrome이 설치되어있지 않은 환경은 isAppInstalled 메서드로 찾아보면 되겠으나, 일각에서 해당 메서드도 문제가 많다해서 사용하지 않을 예정

profile
내 지식을 공유할 수 있는 대담함

8개의 댓글

comment-user-thumbnail
2024년 7월 31일

안녕하세요
올려주신 글 잘 보았습니다만 제가 잘 이해가 안되서 그러는데
나이스인증 관련된 백엔드와 리액트 네이티브 쪽 코드 전부 볼 수 있을까용?

1개의 답글
comment-user-thumbnail
2024년 8월 1일

혹시 그럼 나이스페이도 연동해보셨을까요?

1개의 답글
comment-user-thumbnail
2024년 12월 5일

다시왔습니다 ㅠㅠ

리액트네이티브로 인증 창 부터 어떻게 띄우는지 잘모르겠습니다

코드는 아니라도 진행 플로우 알수 있을까요?

백엔드가 node라서 여기에 jsp를 만들어서 리액트네이티브 웹뷰에서 호출하는걸까요?

주변에 아시는분들도 없어서 힘드네요

1개의 답글