AWS SNS를 사용한 FCM
나는 AWS
내 안드로이드 프로젝트에 리소스를 사용하고 있으며, 내 프로젝트에 푸시 알림 서비스를 추가 할 계획 AWS SNS
입니다. 나는 이것들에 대해 한두 가지를 제외하고는 어떤 질문도 찾지 못했지만 설명이 명확하지 않았습니다.
1. AWS
지원 FCM
합니까? SNS
와 작업 GCM
. 그러나 Google은 GCM
. 나는 AWS
지원을 찾지 못했습니다 FCM
.
2. AWS
푸시 알림을 보낸 후에도 메시지 (또는 데이터)를 데이터베이스에 저장합니까?
3. SNS 애플리케이션 플랫폼에 FCM API 키를 넣으려고했는데 잘못된 매개 변수가 표시되는 이유는 무엇입니까?
FCM은 GCM과 역 호환됩니다. AWS에서 FCM을 설정하는 단계는 GCM 설정 절차 와 동일 하며 (적어도 현재는) FCM이 서버 측 구성과 관련하여 GCM 및 SNS와 투명하게 작동합니다.
그러나data
페이로드를 Android 장치 로 보내는 경우 확장 되는 클라이언트 측 서비스 를 구현하지 않는 한 페이로드가 처리되지 않습니다 FirebaseMessagingService
. AWS 콘솔의 기본 JSON 메시지 생성기 data
는 앞서 언급 한 서비스가 구현되지 않는 한 앱에서 무시되는 메시지를 보냅니다 . 초기 테스트를 위해이 문제를 해결하기 위해 notification
장치에서 수신 할 사용자 지정 페이로드를 제공 할 수 있습니다 (앱이 포 그라운드에 있지 않은 경우).
있다 GCM-FCM 마이그레이션 지침 Google에서 제공하는 그러나 당신이해야 변경 사항이 앱 측에 주로있다.
SNS를 통해 앱에서 GCM / FCM을 테스트하기 위해 따라야하는 단계는 다음과 같습니다.
- 크리에이트 SNS에서 플랫폼 응용 프로그램 은 AS Google 클라우드 메시징 (GCM)를 선택, 푸시 알림 플랫폼 , 그리고 제공하는 서버 API 키 에서 API 키 필드.
- 플랫폼 애플리케이션을 선택하고 플랫폼 엔드 포인트 생성 버튼을 클릭합니다.
- 앱에서 생성 한 InstanceID ( Device Token )를 제공합니다 . Android 앱에서이를 확인
FirebaseInstanceIDService
하려면onTokenRefresh
메서드를 확장 하고 재정의 해야합니다 . 당신은 일단 이 작업을 수행 한 유엔은-설치하고 응용 프로그램을 다시 설치하고 토큰은 첫 번째 부팅에 안드로이드 Studio에서 디버그 콘솔에 인쇄해야합니다. - 엔드 포인트 추가 버튼을 클릭 합니다.
- 플랫폼 애플리케이션에 대한 ARN 링크를 클릭하십시오.
- 장치에 대해 새로 생성 된 엔드 포인트를 선택하고 엔드 포인트에 게시 버튼을 클릭합니다.
- json으로 선택 메시지 형식을 하고 클릭 JSON 메시지 생성 버튼을 클릭합니다.
- 테스트 메시지를 입력하고 JSON 생성 버튼을 클릭 합니다.
- 이제 "gotcha 부분"이 나옵니다.
SNS에서 생성되는 메시지는 다음과 같은 형식입니다.
{
"GCM": "{ \"data\": { \"message\": \"test message\" } }"
}
앞서 언급했듯이 data
페이로드를 수신 할 서비스가 구현되지 않은 경우 페이로드가 무시됩니다. 너무 많은 코드를 작성하지 않고 테스트하고 notification
싶으 므로 대신 페이로드를 보내야합니다 . 이렇게하려면 JSON 메시지를 읽기로 변경하면됩니다.
{
"GCM": "{ \"notification\": { \"text\": \"test message\" } }"
}
이 작업을 마치면 앱이 장치에서 실행되고 있지 않은지 확인하고 메시지 게시 버튼을 누르십시오. 이제 장치에 알림 팝업이 표시됩니다.
물론 Amazon SNS API를 통해이 모든 작업을 프로그래밍 방식으로 수행 할 수 있지만 모든 예제는 data
페이로드 를 사용하는 것으로 보이 므로이를 염두에두고 사용 사례에 적합한 페이로드를 생성해야합니다.
Now you can go to your firebase console (https://console.firebase.google.com/) select your project, click the gear icon and choose project settings, then click on the cloud messaging tab...
You'll see the legacy Server Key which is the GCM API Key and you'll have the option to generate new Server Keys which are the FCM versions
SNS will accept both versions but their menu option is still categorizing it under GCM
Here is picture for your reference:
Note that you can "accidentally" remove your Server Keys but the Legacy server key is not deletable. Also, if you click the add server key button, you'll get a new server key BELOW the first one, WITH NO WARNING! ...Nice job Google ;)
I tried to use solution with notification payload instead of data, but I did not receive push notifications on the mobile device. I found this tutorial https://youtu.be/iBTFLu30dSg with English subtitles of how to use FCM with AWS SNS step by step and example of how to send push notifications from AWS console and implement it on php with aws php sdk. It helped me a lot.
One more additional note to Nathan Dunn's great answer. How to send data with the notification from SNS to Firebase.
We need to add data to the Json (inside the notification):
{
"default": “any value",
"GCM": "{ \"notification\": { \"body\": \”message body\”, \”title\”: \”message title \”, \"sound\":\"default\" } , \"data\" : {\”key\" : \”value\", \”key2\" : \”value\” } }”
}
In your FirebaseMessagingService implementation (Xamarin example)
public override void OnMessageReceived(RemoteMessage message)
{
try
{
var body = message?.GetNotification()?.Body;
var title = message?.GetNotification()?.Title;
var tag = message?.GetNotification()?.Tag;
var sound = message?.GetNotification()?.Sound;
var data = message?.Data
foreach (string key in data.Keys)
{
// get your data values here
}
}
catch (Exception e)
{
}
}
Just an additional note to Nathan Dunn's Answer: to add sound use the following JSON message
{
"GCM": "{ \"notification\": { \"text\": \"test message\",\"sound\":\"default\" } }"
}
It took me a while to figure out how to send the notification with the right payload (publish to topic). So I will put it here.
private void PublishToTopic(string topicArn)
{
AmazonSimpleNotificationServiceClient snsClient =
new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.EUWest1);
PublishRequest publishRequest = new PublishRequest();
publishRequest.TopicArn = topicArn;
publishRequest.MessageStructure = "json";
string payload = "\\\"data\\\":{\\\"text\\\":\\\"Test \\\"}";
publishRequest.Message = "{\"default\": \"default\",\"GCM\":\"{" + payload + "}\"}";
PublishResponse publishResult = snsClient.Publish(publishRequest);
}
Amazon does support FCM as all previous code has been migrated from GCM to FCM. Below article explains in detail.
To answer the questions:
- AWS SNS does support FCM.
- No AWS does not store messages after sending push notifications.
For a detailed tutorial on setting up FCM with SNS please read this article.
참고URL : https://stackoverflow.com/questions/38300450/fcm-with-aws-sns
'developer tip' 카테고리의 다른 글
Vim에서 자동 완성 후 미리보기 창을 어떻게 자동으로 제거합니까? (0) | 2020.09.07 |
---|---|
Subversion에 커밋 한 후 "프로젝트의 종속성을 업데이트 할 수 없습니다" (0) | 2020.09.07 |
많은 정적 메서드를 사용하는 것이 나쁜가요? (0) | 2020.09.07 |
엔터티 프레임 워크 코드에서 먼저 여러 열에 KeyAttribute를 사용하는 방법 (0) | 2020.09.07 |
두 개체를 비교하고 차이점 찾기 (0) | 2020.09.07 |