Skip to content

Latest commit

ย 

History

History
98 lines (62 loc) ยท 3.94 KB

webview.md

File metadata and controls

98 lines (62 loc) ยท 3.94 KB

Flutter์—์„œ ์›น๋ทฐ(Web View) ์‚ฌ์šฉํ•˜๊ธฐ


  1. ์›น๋ทฐ ์‚ฌ์šฉํ•˜๊ธฐ: webview_flutter ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
  2. ์›น๋ทฐ์—์„œ HTTP ํ”„๋กœํ† ์ฝœ ํ—ˆ์šฉํ•˜๊ธฐ

1. ์›น๋ทฐ ์‚ฌ์šฉํ•˜๊ธฐ: webview_flutter ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

1-1. ์›น๋ทฐ

์›น๋ทฐ(Web View)๋ž€ Android๋‚˜ iOS ์•ฑ์—์„œ ์›นํŽ˜์ด์ง€๋ฅผ ์ž„๋ฒ ๋“œํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ฐ€์ ธ์™€ ๋ทฐ(View)๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค. ๊ฐ OS์— ๋‚ด์žฅ๋˜์–ด์žˆ๋Š” ์›น๋ธŒ๋ผ์šฐ์ €๋ฅผ ํ†ตํ•ด ์›นํŽ˜์ด์ง€๋ฅผ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€๋Šฅํ•œ ๊ธฐ๋Šฅ์ด์ฃ . ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ์€ ๋†’์€ ์„ฑ๋Šฅ๊ณผ ๋ถ€๋“œ๋Ÿฌ์šด ์‚ฌ์šฉ์„ฑ์ด ๊ฐ•์ ์ด์ง€๋งŒ, ์ฝ˜ํ…์ธ ๊ฐ€ ์ˆ˜์ •๋˜์–ด ๋ฐฐํฌ๋  ๋•Œ๋งˆ๋‹ค ์‚ฌ์šฉ์ž๊ฐ€ ์•ฑ ์—…๋ฐ์ดํŠธ๋ฅผ ํ•ด์•ผํ•œ๋‹ค๋Š” ์ ์€ ๋‹จ์ ์ž…๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ๊ด€์ ์—์„œ OS ํ˜ธํ™˜์„ฑ๋„ ๋‹จ์ ์ด ๋  ์ˆ˜ ์žˆ๊ณ ์š”. ์›น๋ทฐ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ด๋Ÿฌํ•œ ๋‹จ์ ๋“ค์„ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ, ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ์ฒ˜๋Ÿผ ๋Š๊ปด์งˆ ์ •๋„๋กœ ์›น๋ทฐ์—์„œ์˜ ๋™์ž‘์„ ์ตœ์ ํ™”ํ•  ํ•„์š”๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.


1-2. webview_flutter

iOS ์•ฑ ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ๋Š” WKWebView, Android ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ๋Š” WebView ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด ์›น๋ทฐ๋ฅผ ์ง€์›ํ•˜๋Š”๋ฐ์š”, Flutter์—์„œ ์›น๋ทฐ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด webview_flutter์™€ ๊ฐ™์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฌธ์„œ์— ๋”ฐ๋ฅด๋ฉด, webview_flutter์—์„œ ์ œ๊ณตํ•˜๋Š” WebView ์œ„์ ฏ์„ ์‚ฌ์šฉํ•˜์—ฌ ์›นํŽ˜์ด์ง€๋ฅผ ์ž„๋ฒ ๋“œํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ ํ›„ ์•ฑ์„ ๋นŒ๋“œํ•˜๋ฉด iOS์˜ WKWebView, Android์˜ WebView ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™๊ฒŒ ๋นŒ๋“œ๋ฉ๋‹ˆ๋‹ค.


On iOS the WebView widget is backed by a WKWebView; On Android the WebView widget is backed by a WebView.


1-3. iOS ์‚ฌ์ „์ค€๋น„: o.flutter.embedded_views_preview

ios/Runner/Info.plist ํŒŒ์ผ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ • ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ํฐ ํ™”๋ฉด์ด ๋‚˜์˜ต๋‹ˆ๋‹ค.

<key>io.flutter.embedded_views_preview</key>
<string>YES</string>

1-4. WebView ์œ„์ ฏ ์‚ฌ์šฉ๋ฒ•

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ๋ฒ•์€ ๋งค์šฐ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. WebView ์œ„์ ฏ์„ ์‚ฌ์šฉํ•˜๊ณ , ๋ณด์—ฌ์ค„ ์›นํŽ˜์ด์ง€์˜ URL์„ ์ง€์ •ํ•ด์ค๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  javascriptMode ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ JavaScript ์‚ฌ์šฉ์„ ํ—ˆ์šฉํ•ด์ฃผ์–ด์•ผํ•˜๋Š”๋ฐ์š”, Android์™€ iOS์˜ ์›น๋ทฐ์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ JavaScript๋Š” ์‚ฌ์šฉ ์ค‘์ง€๋˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ํ•˜๋‚˜ ๋” ์ฃผ์˜ํ•  ์ ์€ ์›น๋ทฐ๋Š” HTTPS ํ”„๋กœํ† ์ฝœ๋งŒ ์ง€์›ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๊ณ ์š”, ํ…Œ์ŠคํŠธ ๋“ฑ์„ ์œ„ํ•ด ํŠน๋ณ„ํžˆ HTTP ํ”„๋กœํ† ์ฝœ์„ ์ง€์›ํ•ด์•ผํ•œ๋‹ค๋ฉด ๋ณ„๋„์˜ ์„ค์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

// ..

WebView(
    initialUrl: 'https://flutter.dev',
    javascriptMode: JavascriptMode.unrestricted,
)


2. ์›น๋ทฐ์—์„œ HTTP ํ”„๋กœํ† ์ฝœ ํ—ˆ์šฉํ•˜๊ธฐ

2-1. Android์—์„œ HTTP ํ”„๋กœํ† ์ฝœ ํ—ˆ์šฉํ•˜๊ธฐ

/android/app/src/main/AndroidManifest.xml ํŒŒ์ผ์— ๋‹ค์Œ ์„ค์ •์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

<application
        android:name="io.flutter.app.FlutterApplication"
        android:label="flutterdemo"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true">

2-2. iOS์—์„œ HTTP ํ”„๋กœํ† ์ฝœ ํ—ˆ์šฉํ•˜๊ธฐ

/ios/Runner/Info.plist ํŒŒ์ผ์— ๋‹ค์Œ ์„ค์ •์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
  <key>NSAllowsArbitraryLoadsInWebContent</key>
  <true/>
</dict>


References