반응형

리액트 네이티브 프로젝트를 ios 에뮬레이터에서 실행 시 fetch로 API를 호출하는 부분에서 [TypeError: Network request failed] 에러를 만날 수 있다. ios 에뮬레이터는 기본적으로 http로 되어있는 api 호출을 막아둔다. 그래서 이것을 허용해줘야 한다.
- 내 상황: localhost로 띄워놓은 API 호출
- 해결방법: info.plist 파일 수정
<key>NSAppTransportSecurity</key>
<dict>
//////////////////////////////// 여기서부터 ////////////////////////////////
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
//////////////////////////////// 여기까지 추가 ////////////////////////////////
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>반응형
'ReactNative' 카테고리의 다른 글
| [React Native] 실제 기기 구동 시 @expo/vector-icons 아이콘 안나옴. (0) | 2024.07.05 |
|---|---|
| [React Native] 실제 기기(아이폰) 연결해서 프로젝트 구동하기 (2) | 2024.07.05 |
| [React Native] 탭 간 이동시 탭에 쌓여있는 스택 새로고침/초기화하기 (0) | 2024.06.11 |
| [React Native] 시뮬레이터 기종 지정하기 (0) | 2024.06.11 |
| [React Native]error Failed to build iOS project. "xcodebuild" exited with error code '65'. (0) | 2024.05.16 |
