๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿพ ๊ฐœ๋ฐœ ๐Ÿพ/Flutter

[Flutter] ์นด์นด์˜ค ๋กœ๊ทธ์ธํ•˜๊ธฐ (iOS/Android)

๋ฐ˜์‘ํ˜•

1. kakao developer ์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ๋กํ•˜๊ธฐ

- ๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฆ„

  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฆ„ ๋“ฑ๋ก

 

- ์‚ฌ์—…์ž๋ช…

  ์‚ฌ์—…์ž ๋ช…์ด ์—†์–ด์„œ ์šฐ์„  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฆ„๊ณผ ๋™์ผํ•˜๊ฒŒ ๋“ฑ๋กํ–ˆ์Šต๋‹ˆ๋‹ค.

 

 

 

 

 

 

 

2. pubspec.yaml ํŒŒ์ผ์— ์˜์กด์„ฑ ์„ค์ •

dependencies
  kakao_flutter_sdk_user: ^1.2.1 # ์นด์นด์˜ค ๋กœ๊ทธ์ธ

pubspec.yaml ํŒŒ์ผ์— ํ•ด๋‹น ์˜์กด์„ฑ์„ ์„ค์ •ํ•ด์ค€ ํ›„  $ flutter pub get ์‹คํ–‰ํ•ด ์ค๋‹ˆ๋‹ค.

 

  • ์—๋Ÿฌ ๋ฐœ์ƒ1 : Automatically assigning platform `iOS` with version `9.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See`https://guides.cocoapods.org/syntax/podfile.html#platform`
    • ํ•ด๊ฒฐ๋ฐฉ๋ฒ•
      PodFile ์—์„œ target platform์„ ‘9.0’ ์œผ๋กœ ๋ฐ”๊พธ์–ด ์ฃผ์ž

 

  • ์—๋Ÿฌ ๋ฐœ์ƒ2 : [!] CocoaPods could not find compatible versions for pod "kakao_flutter_sdk_common": In Podfile: kakao_flutter_sdk_common (from .symlinks/plugins/kakao_flutter_sdk_common/ios)
    Specs satisfying the kakao_flutter_sdk_common (from .symlinks/plugins/kakao_flutter_sdk_common/ios) dependency were found, but they required a higher minimum deployment target.
    • ํ•ด๊ฒฐ๋ฐฉ๋ฒ•
      kakao_flutter_sdk_common์€ iOS ๋ฒ„์ „ '11.0'์„ ์ตœ์†Œํ•œ์œผ๋กœ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. 
      ๋”ฐ๋ผ์„œ Podfile์˜ ํƒ€๊นƒ ๋ฒ„์ „์„ ๋‹ค์‹œ ํ•œ๋ฒˆ ๋ฐ”๊พธ์–ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

 

 

 

 

 

 

 

3. Flutter ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ ํ‚ค ์„œ๋ช…

- kakao developer -> ๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ -> ์•ฑ์„ค์ • -> ์•ฑ ํ‚ค์—์„œ ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ ํ‚ค๋ฅผ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

  ** ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ ํ‚ค๋Š” ๋’ค์—์„œ๋„ ๊ณ„์† ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

 

- lib/main.dart

  ์œ„์—์„œ ๋ณต์‚ฌํ•œ ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ ํ‚ค๋ฅผ ๋ถ™์–ด ๋„ฃ์–ด์ค๋‹ˆ๋‹ค.

void main() {
  KakaoSdk.init(nativeAppKey: '${YOUR_NATIVE_APP_KEY}');
  runApp(const MyApp());
}

 

 

 

 

 

 

 

4. ํ”Œ๋žซํผ ์ •๋ณด ์ž…๋ ฅ ๋ฐ ์„ค์ • - Android 

kakao developer์—์„œ ๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ -> ์•ฑ ์„ค์ • -> ํ”Œ๋žซํผ -> Andoird ์ˆ˜์ • 

- ํŒจํ‚ค์ง€๋ช…

   android/app/src/main/AndroidManifest.xml ํŒŒ์ผ์˜ package=${ํŒจํ‚ค์ง€๋ช…} 

   ${ํŒจํ‚ค์ง€๋ช…} ์„ ์œ„์˜ ํŒจํ‚ค์ง€๋ช…์— ์ž…๋ ฅํ•˜์—ฌ ์ค๋‹ˆ๋‹ค.

 

- ๋งˆ์ผ“ URL 

   ์ž…๋ ฅํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค.

 

- ํ‚คํ•ด์‹œ

https://developers.kakao.com/docs/latest/ko/getting-started/sdk-android#add-key-hash

## Mac ๋””๋ฒ„๊ทธ ํ‚ค ํ•ด์‹œ
$ keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android | openssl sha1 -binary | openssl base64

## Windows ๋””๋ฒ„๊ทธ ํ‚ค ํ•ด์‹œ
$ keytool -exportcert -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore -storepass android -keypass android | openssl sha1 -binary | openssl base64

terminal์—์„œ ์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ ํ‚ค๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค. ์–ป์€ ํ‚ค๋ฅผ ํ‚คํ•ด์‹œ ์นธ์— ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

 

- ์ธํ„ฐ๋„ท ์‚ฌ์šฉ ๊ถŒํ•œ

   android/app/src/main/AndroidManifest.xml ์— ์ธํ„ฐ๋„ท ์‚ฌ์šฉ ๊ถŒํ•œ ์ถ”๊ฐ€

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sample">
 
    <!-- ์ธํ„ฐ๋„ท ์‚ฌ์šฉ ๊ถŒํ•œ ์„ค์ •-->
    <uses-permission android:name="android.permission.INTERNET" />

    <application
    android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
    ...

- ์•ฑํ‚ค ์„ค์ •

${Native_APP_KEY} ๋ถ€๋ถ„์—  ๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ํ•ด๋‹นํ•˜๋Š” ์•ฑ ํ‚ค๋ฅผ ๋“ฑ๋กํ•ด์ค๋‹ˆ๋‹ค.

					
			...
        </activity>
				

        <!-- ์นด์นด์˜ค ์•ฑ ํ‚ค ์„ค์ • --> 
        <activity android:name="com.kakao.sdk.flutter.AuthCodeCustomTabsActivity">
            <intent-filter android:label="flutter_web_auth">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="kakao${NATIVE_APP_KEY}" android:host="oauth"/>
            </intent-filter>
        </activity>

       
        <meta-data
            ...

 

 

 

 

 

 

 

5. ํ”Œ๋žซํผ ์ •๋ณด ์ž…๋ ฅ ๋ฐ ์„ค์ • - iOS

kakao developer์—์„œ ๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ -> ์•ฑ ์„ค์ • -> ํ”Œ๋žซํผ -> iOS ์ˆ˜์ • 

- ๋ฒˆ๋“ค ID

Runner -> Signing & Capabilities ์—์„œ Bundle identifier ๋ณต์‚ฌ ํ›„ ๋ฒˆ๋“คID ์ž…๋ ฅ

- ์•ฑ ์‹คํ–‰ ํ—ˆ์šฉ ๋ชฉ๋ก ์„ค์ •ํ•˜๊ธฐ

   Info.plist ํŒŒ์ผ์— ์•„๋ž˜์˜ ์ฝ”๋“œ์™€ ๊ฐ™์€ Array ํƒ€์ž…์˜ Keyd์™€ Value๋ฅผ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. ์ด ์„ค์ •์€ ์‚ฌ์šฉ์ž ์ •๋ณด ๋ณดํ˜ธ๋ฅผ ์œ„ํ•œ OS์ •์ฑ…์— ๋”ฐ๋ผ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

<key>LSApplicationQueriesSchemes</key>
  <array>
      <!-- ์นด์นด์˜คํ†ก์œผ๋กœ ๋กœ๊ทธ์ธ -->
      <string>kakaokompassauth</string>
  </array>

 

- URL Schemes ์„ค์ •ํ•˜๊ธฐ

   Xcode ์‹คํ–‰ ํ›„ Runner → Info → URL Types → (+์•„์ด์ฝ˜ ํด๋ฆญ)

   → URL Schemes ์— kakao${NATIVE_APP_KEY} ํ˜•์‹์œผ๋กœ ์ž…๋ ฅํ•ด์ค๋‹ˆ๋‹ค.

       kakao developer -> ๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ -> ์•ฑ์„ค์ • -> ์•ฑ ํ‚ค ์—์„œ NATIVE_APP_KEY๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

 

 

 

 

 

 

 

6. ์นด์นด์˜ค ๋กœ๊ทธ์ธ ๊ด€๋ฆฌ์ž ์„ค์ • (KOE004)

- ์นด์นด์˜ค ๋กœ๊ทธ์ธ ํ™œ์„ฑํ™” 

kakao Developer -> ๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ -> ์นด์นด์˜ค ๋กœ๊ทธ์ธ ์—์„œ ์นด์นด์˜ค ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”์‹œํ‚ต๋‹ˆ๋‹ค.

- OpenId Connect ํ™œ์„ฑํ™”

ํ™œ์„ฑํ™” ํ•ด์•ผ์ง€ ํ† ํฐ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

 

 

 

 

 

 

 

7. AccessToken ๋ฐ›์•„์˜ค๊ธฐ

- ์นด์นด์˜ค ๋™์˜ํ•ญ๋ชฉ ์ฒดํฌ

๋™์˜ํ•ญ๋ชฉ์„ ํ•„์ˆ˜๋กœ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ์•ฑ ์„ค์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋น„์ฆˆ๋‹ˆ์Šค ์•ฑ์€ ์•„์ด์ฝ˜ ๋“ฑ๋ก ํ›„ ๊ฐ„๋‹จํžˆ ์ „ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

 

 

 

 

 

 

 

8. AccessToken ๋ฐ›์•„์˜ค๊ธฐ

  /**
   * ์นด์นด์˜คํ†ก ์—ด๊ธฐ
   */
  void tabSignUpKakaoBtn(BuildContext context) async {
    try {
      if (await isKakaoTalkInstalled()) {
        await UserApi.instance.loginWithKakaoTalk();
      } else {
        await UserApi.instance.loginWithKakaoAccount();
      }
      getKakaoAccessToken();
    } catch (error) {
      print(error.toString());
    }
  }

  /**
   *  kakao accessToken ๋ฐ›์•„์˜ค๊ธฐ
   */
  void getKakaoAccessToken () async {
    var tokenManager = await TokenManagerProvider.instance.manager.getToken();
    print(tokenManager?.accessToken);
  }

 

 

 

 

 

  • Could not register as server for FlutterObservatoryPublisher์‚ฝ์งˆํ•˜๋‹ค๊ฐ€ ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑํ‚ค๋ฅผ ์žฌ๋ฐœ๊ธ‰ ๋ฐ›๊ณ  ํ•ด๊ฒฐํ•˜์˜€๋‹ค.

 

 

https://developers.kakao.com/docs/latest/ko/kakaologin/flutter

 

Kakao Developers

์นด์นด์˜ค API๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋‹ค์–‘ํ•œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•ด๋ณด์„ธ์š”. ์นด์นด์˜ค ๋กœ๊ทธ์ธ, ๋ฉ”์‹œ์ง€ ๋ณด๋‚ด๊ธฐ, ์นœ๊ตฌ API, ์ธ๊ณต์ง€๋Šฅ API ๋“ฑ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

developers.kakao.com

 

 

 

 

 

 

๋ฐ˜์‘ํ˜•