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 14387
공지 [UX Summit 요약] 오른쪽 클릭은 옳다 (Right Click is Right) 관리자 2020.11.16 13023
공지 [10.4 시드니] What's NEW! 신기능 자세히 보기 관리자 2020.05.27 15532
공지 RAD스튜디오(델파이,C++빌더) - 고객 사례 목록 관리자 2018.10.23 21064
공지 [데브기어 컨설팅] 모바일 앱 & 업그레이드 마이그레이션 [1] 관리자 2017.02.06 22297
공지 [전체 목록] 이 달의 기술자료 & 기술레터 관리자 2017.02.06 17933
공지 RAD스튜디오(델파이, C++빌더) - 시작하기 [1] 관리자 2015.06.30 38228
공지 RAD스튜디오(델파이,C++빌더) - 모바일 앱 개발 사례 (2020년 11월 업데이트 됨) 험프리 2014.01.16 173741
274 [베를린 U1] TGrid가 네이티브 렌더링을 지원해 더 부드럽고 강력한 기능을 제공합니다. file 험프리 2016.09.20 554
273 [베를린 U1] 윈도우 태스크바 알림의 뱃지를 제어할 수 있습니다. 험프리 2016.09.20 677
272 윈도우 10 Anniversary 업데이트와 RAD Studio file 관리자 2016.09.09 832
271 RAD 스튜디오(델파이, C++빌더) 웹개발 방법(WebBroker, IntraWeb) 험프리 2016.09.07 1826
270 TeeChart 컴포넌트를 통해 다양한 차트 및 그래프로 데이터를 출력할 수 있습니다. file 험프리 2016.08.30 5198
269 [발표자료] 20160830 나만의 C++애플리케이션 완성하기 with C++빌더 험프리 2016.08.26 1915
268 이 달의 기술자료 - 2016년 09월 file 험프리 2016.08.25 588
267 [마이그레이션 사례] 감리교신학대학교 험프리 2016.08.25 1433
266 [로드맵] RAD 스튜디오 로드맵(2016년 8월) file 험프리 2016.08.12 1979
265 FireDAC 성능 비교(BDE, dbGO(ADO), dbExpress, FireDAC) 험프리 2016.08.09 1748
264 퀵레포트 보고서 엑셀로 내보내기(저장하기) [1] 험프리 2016.08.01 1650
263 [마이그레이션] 써드파티 컴포넌트 마이그레이션 방안 안내 험프리 2016.07.26 1418
262 이 달의 기술자료 - 2016년 07월 file 험프리 2016.06.30 2034
261 [업데이트][핫픽스][10.1 베를린] 갤럭시 S7 Edge(안드로이드 6.0.1) 디버깅이 되지않는 이슈 패치 험프리 2016.05.27 672
260 10.1 베를린 부터는 리본 컨트롤을 겟잇 패키지 매니저에서 설치할 수 있습니다. 험프리 2016.05.27 510
259 코드사이트(CodeSite)로 로그를 기록하며 프로그램의 문제를 파악할 수 있습니다. file 험프리 2016.05.26 2658
258 [베를린] TBufferedFileStream을 이용해 TFileStream 보다 더 빠르게 파일을 읽고, 쓸수 있습니다. file 험프리 2016.05.09 3058
257 [필독] Berlin Dialog 사용법 상당부분 변경 및 기능추가 (소스링크추가) [1] c2design 2016.05.04 852
256 [업데이트][핫픽스][10.1 베를린] 데이터스냅(DataSnap) ApplyUpdates 핫픽스 험프리 2016.04.28 866
255 이 달의 기술자료 - 2016년 05월 file 험프리 2016.04.26 655