Наше мобильное приложение написано с использованием ReactNative. Нам нужно иметь возможность обрабатывать ответ на push-уведомление, даже если приложение свернуто или работает в фоновом режиме, поэтому необходим собственный код.
Вот код Android:
OSNotification raw payload: {
"google.delivered_priority": "high",
"google.sent_time": 9999999999,
"google.ttl": 9999999999,
"google.original_priority": "high",
"custom": "{\"i\":\"xxxxxxxxxx\",\"u\":\"xxxxxxxxxx:\/\/transaction\/xxxxxxxxxx\"}",
"google.product_id": 9999999999,
"pri": "10",
"from": "xxxxxxxxxx",
"alert": "Your invoice has been paid by the customer. Tap here to view the details.",
"title": "Invoice Paid",
"google.message_id": "xxxxxxxxxx",
"google.c.sender.id": "xxxxxxxxxx"
}
Почему объект дополнительных данных имеет значение NULL? Я не работаю на внутренней стороне, и насколько я понимаю, объект data уже отправлен. Вот код (Go):
Наше мобильное приложение написано с использованием ReactNative. Нам нужно иметь возможность обрабатывать ответ на push-уведомление, даже если приложение свернуто или работает в фоновом режиме, поэтому необходим собственный код. Вот код Android: [code]import android.util.Log;
@Keep public class OSNotificationService implements INotificationServiceExtension{
@Override public void onNotificationReceived(@NonNull INotificationReceivedEvent event) { IDisplayableMutableNotification notif = event.getNotification(); System.out.println("OSNotificationService raw payload: "+notif.getRawPayload()); if (notif.getAdditionalData() != null) { System.out.println("OSNotificationService additional data: "+notif.getAdditionalData().toString()); JSONObject jsObj = notif.getAdditionalData(); } else { System.out.println("OSNotificationService additional data: null"); } event.getNotification().display(); } } [/code] При запуске приложения на эмуляторе Android и получении уведомления OneSignal я увидел это в logcat (это правильно): [code]OSNotification raw payload: { "google.delivered_priority": "high", "google.sent_time": 9999999999, "google.ttl": 9999999999, "google.original_priority": "high", "custom": "{\"i\":\"xxxxxxxxxx\",\"u\":\"xxxxxxxxxx:\/\/transaction\/xxxxxxxxxx\"}", "google.product_id": 9999999999, "pri": "10", "from": "xxxxxxxxxx", "alert": "Your invoice has been paid by the customer. Tap here to view the details.", "title": "Invoice Paid", "google.message_id": "xxxxxxxxxx", "google.c.sender.id": "xxxxxxxxxx" } [/code] Проблема в этой строке: [code]System.out.println("OSNotificationService additional data: null"); [/code] Почему объект дополнительных данных имеет значение NULL? Я не работаю на внутренней стороне, и насколько я понимаю, объект data уже отправлен. Вот код (Go): [code]type NotificationPayload struct { AppID string `json:"app_id"` Contents map[string]string `json:"contents"` Headings map[string]string `json:"headings"` Priority int `json:"priority"` URL string `json:"url"` TTL int `json:"ttl"` IncludeAliases map[string][]string `json:"include_aliases"` TargetChannel string `json:"target_channel"` IosSound string `json:"ios_sound,omitempty"` AndroidChannelID string `json:"android_channel_id,omitempty"` Data map[string]interface{} `json:"data"` }
// Only set optional fields if they are provided if iosSound != nil { data.IosSound = *iosSound } if androidChannelID != nil { data.AndroidChannelID = *androidChannelID }
body, err := json.Marshal(data) if err != nil { return fmt.Errorf("failed to marshal data: %v", err) }