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
514 [FireDAC Skill Sprints] 2. FireDAC으로 DBMS 사용 내역 추적, 모니터링 하기 Humphery 2015.03.07 1538
513 [써드파티 컴포넌트/툴/플러그인] XE7을 지원하는 컴포넌트 정리 관리자 2014.12.23 1535
512 이미지와 애니메이션 효과 적용하기: 파이어몽키 코스북 8장 file 관리자 2014.07.23 1528
511 HD 애플리케이션 만들기(파이어몽키 활용): 파이어몽키 코스북 5장 file 관리자 2014.07.17 1526
510 [XE7] 안드로이드 5.0(롤리팝) 지원 핫픽스 [2] Humphery 2015.01.12 1510
509 이 달의 기술자료 - 2021년 09월 file 험프리 2021.08.26 1507
508 [업데이트][HotFix] VCL BMP Buffer Overflow hotfix(취약점 보안패치) Humphery 2014.08.20 1505
507 [FireDAC Skill Sprints] 3. 캐쉬를 이용한 업데이트와 자동증가필드(Identity) 적용 Humphery 2015.03.07 1495
506 [FireDAC Skill Sprints] 4. ArrayDML로 30배 빠르게 데이터 입력하기 Humphery 2015.03.11 1493
505 바이너리 폼파일(*.dfm)을 텍스트 폼파일로 변경하는 도구 Humphery 2015.09.15 1485
504 RAD Studio XE7에서 안드로이드 개선된 내용 [1] 관리자 2014.11.22 1470
503 [윈도우10] RAD Studio XE8로 윈도우 10 애플리케이션 만들기 file Humphery 2015.05.26 1451
502 [팁] TIniFile과 TMemIniFile 사용 험프리 2019.12.04 1449
501 20년된 델파이 앱을 현대식 마이크로서비스 아키텍처로 전환하기 관리자 2019.09.11 1449
500 [발표자료] 20190214 델파이 24주년 기념 세미나: 델파이 앱 현대화 방안 - 다양한 데이터 서비스 연동하기 관리자 2023.04.20 1442
499 [마이그레이션] 써드파티 컴포넌트 마이그레이션 방안 안내 험프리 2016.07.26 1439
498 [마이그레이션 사례] 감리교신학대학교 험프리 2016.08.25 1436
497 [프로그래밍 애피타이저] 6장 프로시저와 함수 file 김원경 2020.04.07 1435
496 [세미나 자료] 20141113 RAD Studio XE7 DeepDive file 관리자 2014.11.14 1429
495 웹에서 어플리케이션 구동하기(ActiveX 사용않고) Humphery 2015.04.09 1428