(27-09-2023, Saat: 16:13)RAD Coder Adlı Kullanıcıdan Alıntı: Merhaba,
Göndereceğiniz bildirim içeriği (JSON formatı) aşağıdaki gibi olmalıdır.
{
"notification": {
"title": "Mobil Uygulama Adınız",
"body": "Hal Kayıt Sistemi ve E-Fatura Sistemini birlikte dijital ortama taşıdık."
},
"data": {
"musteri_id": 325,
"musteri_kodu": "M-2023-0000325",
"unvan": "DelphiCan",
"telefon": "0312 300 00 00"
},
"to": "BildirimAlacakCihazTokenDegeri"
}
Notification kısmında, bildirim başlağı ve mesaj içeriği olur. Data kısmında ise istediğiniz kadar veri ve veri tipi gönderebilirsiniz.
isteği göndermekle ilgili sıkıntı yok aslında. Ben sorunu tam anlatamamış olabilirim. İsteği gönderdikten sonra bildirim giden telefon bildirime tıkladığında gelen içeriğe göre istediğim formu açtırmam lazım. Onu beceremedim. İstek kodum şu şekilde, anahtar tanımlama da yaptım click_action, page gibi. Ama cihaz açılırken bildirim üzerinden bu değerleri nasıl alacağımı çözemedim.
RESTClient1 := TRESTClient.Create(nil);
RESTRequest1 := TRESTRequest.Create(nil);
RESTResponse1 := TRESTResponse.Create(nil);
RESTRequest1.Client := RESTClient1;
RESTRequest1.Response := RESTResponse1;
RESTRequest1.Method := TRESTRequestMethod.rmPOST;
RESTRequest1.Params.AddItem('Authorization', 'key=AAAAd0AiRS8:APA91bEEwVgAep_s64Om2zEDpHlx83MF2OamuIhzx8nA_E0CRHoq0Zujxip97WSWHzSXttnC0WWKna0eQjFLBsOlFGs8a5W8IxDpGGNNRzpOSFxfp3QhYTdJ3p9H***************', pkHTTPHEADER, [poDoNotEncode]);
RESTClient1.BaseURL := 'https://fcm.googleapis.com/fcm/send';
JsonBody := TJSONObject.Create;
JsonNotification := TJSONObject.Create;
JsonData := TJSONObject.Create;
JsonNotification.AddPair('title', gonderici_ad+' Size mesaj gönderdi!');
JsonNotification.AddPair('body', mesaj);
JsonData.AddPair('click_action', 'olayın adı');
JsonData.AddPair('page', '1');
// jsonString := '{"to" : "'+token.Text+'",' +
// '"data" : {' +
// '"gcm.notification.title" : "'' Size mesaj gönderdi!'+'",' +
// '"gcm.notification.body" : "''",' +
// '"gcm.notification.e": "1",'+
// '"gcm.n.dnp": "1",'+
// '"gcm.n.e": "1",'+
// '"collapse_key": "com.embarcadero.Love"'+
// '},}';
JsonBody.AddPair('notification', JsonNotification);
JsonBody.AddPair('data', JsonData);
JsonBody.AddPair('to', alici_gcm);
// result:= JsonBody.ToString;
RESTRequest1.AddBody(JsonBody);
RESTRequest1.Execute;
JsonResponse := RESTResponse1.JSONValue as TJSONObject;
// Result := JsonResponse.ToString;