capacitor-play-games-services 사용법

capacitor-play-games-services 사용법 updated_at: 2023-09-06 17:01

capacitor-play-games-services 사용하기

Capacitor Package install

이제 본격적으로 하이브리드 앱에 play game services를 넣어 보자..
여기서는 capacitor-play-games-services 라는 package를 사용할 것입니다.

github

npm i capacitor-play-games-services

sync

npx cap update
npx cap sync

Android Studio

MainActivity.java

  • GoTo your Android project's MainActivity : android > app > src > main > java > domain name of your project > MainActivity.java
  • 아래 부분 추가
package com.xx.xx;
..........
import gammafp.playgames.PlayGamesPlugin;

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    registerPlugin(PlayGamesPlugin.class);

    // Important, super.onCreate(...) should go down
    super.onCreate(savedInstanceState);
  }
}

game Id 를 string.xml에 넣기

Play Games Console의 Play Games Services setup 에서 관련 Project ID를 획득할 수 있습니다.
Android Studio > Go to plugin capacitor-play-games-services > res > values > string.xml and add the app_id.

<?xml version='1.0' encoding='utf-8'?>
<resources>
  <string translatable="false" name="app_id">658713388096</string>
</resources>

Angular에서 처리하기

import { PlayGames } from 'capacitor-play-games-services';
..........
export class MyComponent {
constructor(
  ) {

  PlayGames.addListener("onSignInStatus", (res) => {
    console.log('onSignInStatus >> res >>', res);
  })

  PlayGames.login().then((response) => {
    console.log('login >> response >>', response);
  });
}
평점을 남겨주세요
평점 : 5.0
총 투표수 : 1