본문 바로가기
  • 포르쉐타고싶다
카테고리 없음

[flutter] url_launcher 에러: Attempt to present <SFSafariViewController: 0x1042b6400> on <SFAuthenticationViewController: 0x103d15800> (from <SFAuthenticationViewController: 0x103d15800>) whose view is not in the window hierarchy. 해결

by 지오ㄴl 2021. 7. 29.

회원가입과 비밀번호찾기 등을 구현하는 대신 카카오 채널을 통해 연결해 놓은 상태이다.

Uri kakaoChannelUri = await TalkApi.instance.channelChatUrl('_fZnrK');

 

카카오로그인과 카카오 채널 연결은 상관없는 내용이고

패션몬스터에서는 카카오로그인 -> 카카오 채널 연결을 이어 구현한 상태이다.

 

카카오로그인

String authCode = await AuthCodeClient.instance.request();

//authCode로 token 확인
print(TAG + 'authCode: ' + authCode);
// getting access token
AccessTokenResponse token = await AuthApi.instance.issueAccessToken(authCode);
AccessTokenStore.instance.toStore(token);

 

카카오 채널 연결

Uri kakaoChannelUri = await TalkApi.instance.channelChatUrl('_fZnrK');
    print(TAG + 'addUrlResult: ' + kakaoChannelUri.toString());

    // 카카오채널로 넘어가기
    bool canLaunched = await canLaunch(kakaoChannelUri.toString());
    print('canLaunched: ' + canLaunched.toString());
    await Future.delayed(Duration(milliseconds: 500));
    final bool succeeded =
    await launch(kakaoChannelUri.toString(), forceSafariVC: false, universalLinksOnly: true);
    if (!succeeded) {
      await launch(kakaoChannelUri.toString(), forceSafariVC: true);
    }

 

그런데 위와 같이 구현하였더니 url_launcher의 launch() 메소드가 실행되지 않는 문제가 발생하였다.

flutter 상에서는 에러도 catch하지 못해 왜 안되는지 알 수가 없는 상황이었다.

 

가장 중요한 것은 이 때

Xcode에서 다시 실행해보는 것이다.

 

Xcode에서 실행해본 결과

아래와 같은 메세지가 나타났다.

 

Attempt to present <SFSafariViewController: 
0x1042b6400> on <SFAuthenticationViewController:
0x103d15800> (from <SFAuthenticationViewController:
0x103d15800>) whose view is not in the window hierarchy.

 

해결

 

이 에러는 위의

카카오로그인의 request 메소드와 

카카오채널 연결에서의 launch 메소드가 둘 다 browser창을 연결하면서

ios 상에서는 충돌이 생겨 뒤의 launch에서 브라우저 창을 띄우지 못하는 문제였다.

 

그래서 두 구현 사이에

await Future.delayed(Duration(milliseconds: 500))

을 삽입하여 둘 사이에 텀을 둠으로써 문제를 해결할 수 있었다.

반응형

댓글