Delphi, C++Builder 및 RAD 스튜디오 10.3.1을 사용해 파이어몽키 안드로이드 앱에서 Firebase 푸시 알림 지원하는 과정은 아래 링크를 참고하세요:

 

 

업그레이된 RAD 스튜디오 10.3.2에서는 더욱 더 간소화된 과정으로 Firebase 푸시 알림을 사용 하실 수 있습니다.

  • Firebase 패치 제공 (10.3.2에 포함)
  • 알림 아이콘 개선
  • Firebase 버전 지원 요구 사항에 맞게 Google Play 서비스 및 지도 업데이트

 

 

Firebase에서 애플리케이션을 활성화하려면, 다음 3단계로 작업을 진행해야 합니다.

  1. Firebase 프로젝트를 만들고 파이어몽키 프로젝트를 Google Firebase 콘솔에 등록
  2. 파이어몽키 프로젝트를 새로 만들거나 기존의 프로젝트에 RAD 스튜디오 10.3.2 푸시 알림 구성
  3. GCM(Google Cloud Messaging)  대신 Firebase를 지원하도록 파이어몽키 프로젝트 변경

 

Firebase 프로젝트 생성 및 Firebase 콘솔에 파이어몽키 프로젝트 등록

1.  Google Firebase 콘솔(https://console.firebase.google.com/)에 접속 후 [New Project]를 클릭 합니다.

 

2.   프로젝트 이름은 임의로 설정(예> FirebaseApp)하고 [Continue] 버튼을 클릭합니다.

 

3. Set up Google Analytics for my project 를 선택하고 [Continue] 버튼을 클릭합니다.

 

4. 구글 분석 계정을 하나 만들어서 입력하시고 [Create Project] 버튼을 클릭합니다.

 

5. 프로젝트가 생성된 후  [Continue] 버튼을 클릭합니다.

 

6. 프로젝트 생성  Project Overview 옆의 톱니바퀴 아이콘 클릭  [Project Settings] 메뉴를 선택해 프로젝트 설정 화면으로

   이동합니다.           

   -       Google Cloud Platform(GCP) Resource Location 가장 가까운 asia-northeast1 추천합니다.

   -       Support Email 입력해 주십시오.


7. 안드로이드 아이콘을 클릭하여 "Android 앱에 Firebase 추가 화면"으로 이동합니다.

 

img.png

 

  8.  등록 단계에서 Android 패키지 이름을 지정  [Register] 버튼을 클릭합니다.

 

    - 파이어몽키 앱의 기본 패키지 이름은 com.embarcadero.프로젝트이름 입니다.

    - 파이어몽키 프로젝트를 FirebaseApp으로 생성 시 com.embarcadero.FirebaseApp으로 생성합니다.

 

img.png

 

9. 구성 파일(google-services.json)을 다운로드 합니다. 

 

img.png

 

다운로드 후 [다음] 버튼 클릭 후 이후 단계는 건너 뛰기를 선택합니다.

 

파이어몽키 프로젝트에 푸시 알림 구성

10. 파이어몽키 프로젝트를 생성(또는 기존 프로젝트 오픈) 합니다.

 

11. Firebase 콘솔에 등록된 프로젝트 이름과 일치하도록 FMX 프로젝트 이름을 변경합니다.

    (이 예제에서는 FirebaseApp으로 설정합니다.)

 

img.png

 

12. 델파이 개발환경에서 Project > Options... > Application > Services 에서 Import 버튼을 클릭하여 google-services.json 추가합니다.

 

아래와 같이 libraries 확장해 보시면 파일 들이 추가  것을 확인 하실  있습니다.

 

img.png

 

13. Project > Options... > Application > Entitlemenet List 탭에서 Receive Push Notifications 옵션을 True로 지정합니다.

 

14. Firebase 이벤트 로그를 표시하기 위해 TMemo 컴포넌트를 폼에 추가하고, MemoLog로 이름을 변경합니다.

 

15. uses절 System.PushNotification을 추가하고  implemetation uses에 다음과 같이 추가합니다.

(안드로이드 플랫폼에서만 사용시에는 $ifdef 문은 생략하셔도 됩니다)

implemetation

uses

{$ifdef android}

   FMX.PushNotification.Android;

{$endif}

 

16. 필요한 변수와 이벤트를 private 영역에 선언합니다.

  private

    FDeviceId: string;

    FDeviceToken: string;

    procedure OnServiceConnectionChange(Sender: TObject;PushChanges: TPushService.TChanges);

    procedure OnReceiveNotificationEvent(Sender: TObject;const ServiceNotification:TPushServiceNotification);

 

17. 다음 Form의 OnCreate 이벤트를 추가해 푸시 알림 서비스 초기화 및 연결을 위한 코드를 구현합니다.

procedure TForm1.FormCreate(Sender: TObject);

var

   PushService: TPushService;

   ServiceConnection: TPushServiceConnection;

   Notifications: TArray<TPushServiceNotification>;

 begin

   PushService :=

   TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.GCM);

   ServiceConnection := TPushServiceConnection.Create(PushService);

   ServiceConnection.Active := True;

   ServiceConnection.OnChange := OnServiceConnectionChange;

   ServiceConnection.OnReceiveNotification := OnReceiveNotificationEvent;

 

   FDeviceId :=

   PushService.DeviceIDValue[TPushService.TDeviceIDNames.DeviceId];

   MemoLog.Lines.Add('DeviceID: ' + FDeviceId);

   MemoLog.Lines.Add('Ready to receive!');

 

   // Checks notification on startup, if application was launched fromcold start

   // by tapping on Notification in Notification Center

   Notifications := PushService.StartupNotifications;

   if Length(Notifications) > 0 then

   begin

       MemoLog.Lines.Add('-----------------------------------------');

       MemoLog.Lines.Add('DataKey = ' + Notifications[0].DataKey);

       MemoLog.Lines.Add('Json = ' + Notifications[0].Json.ToString);

       MemoLog.Lines.Add('DataObject = ' +

       Notifications[0].DataObject.ToString);

       MemoLog.Lines.Add('-----------------------------------------');

   end;

 end;

 

18. 위에 선언된 2개의  이벤트 핸들러를 각각 다음과 같이 작성합니다.

 procedure TForm1.OnReceiveNotificationEvent(Sender: TObject;const ServiceNotification:TPushServiceNotification);

var

   MessageText: string;

 begin

   MemoLog.Lines.Add('-----------------------------------------');

   MemoLog.Lines.Add('DataKey = ' + ServiceNotification.DataKey);

   MemoLog.Lines.Add('Json = ' + ServiceNotification.Json.ToString);

   MemoLog.Lines.Add('DataObject = ' +

   ServiceNotification.DataObject.ToString);

   MemoLog.Lines.Add('---------------------------------------');

 end;

 

procedure TForm1.OnServiceConnectionChange(Sender: TObject;

  PushChanges: TPushService.TChanges);

var

   PushService: TPushService;

 begin

   PushService :=

   TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.GCM);

   if TPushService.TChange.DeviceToken in PushChanges then

   begin

       FDeviceToken :=

       PushService.DeviceTokenValue[TPushService.TDeviceTokenNames.DeviceToken];

       MemoLog.Lines.Add('FireBase Token: ' + FDeviceToken);

       Log.d('Firebase device token: token=' + FDeviceToken);

   end;

   if (TPushService.TChange.Status in PushChanges) and (PushService.Status

     = TPushService.TStatus.StartupError) then

       MemoLog.Lines.Add('Error: ' + PushService.StartupError);

 

 end;

 

Firebase Cloud Messaging 전송테스트

 

19. FMX 앱을 안드로이드 장비에 배포합니다. 실행 시 앱은 자동으로 Firebase에 등록되고, 로그에 디바이스 토큰이 표시됩니다.

 

이미지 2.png

 

 장비에 푸시메시지를 전송하려면 Firebase 토큰이 필요합니다. 로그에 표시된 토큰을 복사합니다.

 

20. 브라우저에서 Google Firebase 콘솔(https://console.firebase.google.com/) 접속 후 앞에서 만든 프로젝트를 선택합니다. 사이드 메뉴의 "성장 > Cloud Messaging" 메뉴를 선택 후 [Send your first message] 버튼을 클릭합니다.

 

img.png

 

 

21. 알림의 제목과 텍스트를 입력하고, [테스트 메시지 전송] 버튼을 클릭합니다.

 

img.png

 

22. 위에서 선택한 Firebase 토큰을 "FCM 등록 토큰 추가" 항목에 입력 후 (+) 버튼 클릭해 토큰을 추가합니다.

[테스트] 버튼을 눌러 메시지를 전송합니다.

 

23. 아래와 같이 해당 토큰을 재사용하는 경우 체크   [Test] 버튼을 눌러 메시지를 전송합니다.

sendMessage2.png

 

 

다음 화면과 같이 전송한 메시지가 안드로이드 화면에 표시되는 것을 확인할 수 있습니다. 또한 메시지는 안드로이드 알림센터에도 표시됩니다.

 

이미지 3.png

 

팁 Project > Options... > Application > Icons 에서 사옹자 지정 알림 아이콘과 액센트 색상을 지정하실 수 있습니다.

 

IconsP.png

 

 

 

 

관련글 & 10.3 리오의 업데이트 버전들

 

번호 제목 글쓴이 날짜 조회 수
공지 [DelphiCon 요약] 코드사이트 로깅 실전 활용 기법 (Real-world CodeSite Logging Techniques) 관리자 2021.01.19 15443
공지 [UX Summit 요약] 오른쪽 클릭은 옳다 (Right Click is Right) 관리자 2020.11.16 13962
공지 [10.4 시드니] What's NEW! 신기능 자세히 보기 관리자 2020.05.27 16499
공지 RAD스튜디오(델파이,C++빌더) - 고객 사례 목록 관리자 2018.10.23 22055
공지 [데브기어 컨설팅] 모바일 앱 & 업그레이드 마이그레이션 [1] 관리자 2017.02.06 23268
공지 [전체 목록] 이 달의 기술자료 & 기술레터 관리자 2017.02.06 18923
공지 RAD스튜디오(델파이, C++빌더) - 시작하기 [1] 관리자 2015.06.30 39257
공지 RAD스튜디오(델파이,C++빌더) - 모바일 앱 개발 사례 (2020년 11월 업데이트 됨) 험프리 2014.01.16 174713
554 [발표자료] 20160830 나만의 C++애플리케이션 완성하기 with C++빌더 험프리 2016.08.26 1919
553 [FireDAC Skill Sprints] 9. LocalSQL: DB에서 가져온 데이터(데이터셋)를 대상으로 다시 SQL쿼리 실행하기 Humphery 2015.04.01 1905
552 멀티-플랫폼 앱 멋지게! 쉽게! 빠르게! 완성하기 - #.1 한번에 멋지게 개발하기 file 험프리 2019.07.09 1886
551 [10.3 리오] IDE가 현대적이고 깔끔하게 업데이트 되었습니다. 관리자 2018.11.14 1886
550 [개발환경 설정] 안드로이드 기기 연결 시 'USB 디버깅 허용' 창이 표시되지 않는 경우 조치 방법 file 험프리 2018.08.21 1868
549 [동영상] 8단계로 완성하는 "2014년 출시 앨범" 앱 개발 "15"분 만에 완료하기 관리자 2014.10.14 1850
548 [튜토리얼] Mobile Tutorials: Mobile Application Development Humphery 2014.06.13 1848
547 [마이그레이션][팁] 유니코드 검토 대상 분석 도구 다운로드 [1] file 험프리 2015.11.16 1845
546 RAD 스튜디오(델파이, C++빌더) 웹개발 방법(WebBroker, IntraWeb) 험프리 2016.09.07 1829
545 손쉬운 데이터 연결 방법(라이브바인딩 활용): 파이어몽키 코스북 6장 file 관리자 2014.07.18 1806
544 RAD Studio XE6 TChart 패치의 건 Humphery 2014.07.31 1793
543 20140424_Developer Direct LIVE! 2014 세미나 세션 자료입니다. 관리자 2014.04.25 1772
» [10.3 리오][업데이트 2] Firebase 안드로이드 앱 푸쉬 알림 - 10.3.2에서 FCM 수신 설정하기 [1] file 김원경 2019.08.21 1757
541 FireDAC 성능 비교(BDE, dbGO(ADO), dbExpress, FireDAC) 험프리 2016.08.09 1755
540 [BaaS] VCL에서 특정사용자에게 GCM/APN 전송하기(FMX도 사용가능) Humphery 2014.07.25 1727
539 [시애틀] BSON(Binary JSON)을 처리하고, JSON 데이터를 스트리밍 모델로 읽고, 쓸수 있습니다. file Humphery 2015.10.05 1718
538 [업데이트][10.2 도쿄][릴리즈 2] 10.2 도쿄 - 릴리즈 2 출시 & 설치방법 안내 file 험프리 2017.12.13 1693
537 [마이그레이션] 컴파일러 버젼 [1] 험프리 2014.08.18 1691
536 멀티-티어 애플리케이션 개발과 배포: 파이어몽키 코스북 9장 file 관리자 2014.07.25 1689
535 [FireDAC Skill Sprints] 6. 전처리: SQL문을 유연하게 작성할 수 있는 Param와 Macro 사용하기 Humphery 2015.03.13 1683