OneSignal Notifications delay

Issue

I have an ionic 2 app running on android with a wordpress site providing the data. I have notifications working with onesignal. The problem is that the notification arrives before the rest API data is updated. The App can take up to a minute to update. Is there a way to delay the onesignal notification? or speed up the wordpress json data?

Solution

I was looking for the same thing. Modified your codes a little and its working fine.

// Send OneSignal Push after some time delay.
add_filter('onesignal_send_notification', 'onesignal_delay_send', 10, 4);
function onesignal_delay_send($fields, $new_status, $old_status, $post) {
    //delay
    $delay = '+25 minutes';

    //replace it with your timezone. Mine is UTC+05:30
    $timezone = 0530;
    
    $current_time = current_time('M d Y H:i:s e+$timezone');
    $future_time = date( 'M d Y H:i:s e+$timezone', strtotime( $delay, strtotime( $current_time ) ) );
  
    // Schedule the notification to be sent in the future
    $fields['send_after'] = $future_time;
  
    return $fields;
}

Answered By – Harry

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published