'No Push Notification Sound on iOS

No push notification sound on iOS - Expo

I'm using Expo push notification API to send push notifications from server to application built using managed workflow. Android and iOS both get the notification with intended content and action, however, there is no notification sound on iOS.

Following is the code snippet to register get the push token (and then it is sent to the backend) -

const token = await Notifications.getExpoPushTokenAsync()

Following registers the event when a push notification is received -

Notifications.setNotificationHandler({
    handleNotification: async () => ({
        shouldShowAlert: true,
        shouldPlaySound: true,
        shouldSetBadge: false
    }),
})

componentDidMount = () => {
    Notifications.addNotificationResponseReceivedListener(this._handleNotification)
}

_handleNotification = resp => {
    try {
        resp = resp.notification.request.content.data.take_to
        if(resp.type == "customer") {
            this.props.navigation.navigate('Messages', { id: resp.customer_id } )
        } else {
            this.props.navigation.navigate("Notification")
        }
    } catch(e) {
        // This handles errors
    }
}

I'm using ExponentPhpSDK to send push notification, and below is snippet from backend -

function pushNotify($recipients, $title, $body, $take_to) {

    if(empty($recipients)) {
        return;
    }
        
    $expo = new Expo();

    if(!empty($take_to)) {
        $data = array(
            "take_to" => $take_to
        );
    }

    $notification = array(
        'title' => $title,
        'body' => $body,
        'data' => json_encode($data)
    );
        
    $expo->notify($recipients, $notification);

}

I have checked app settings, it shows that the sound is enabled, and Android works fine.

How can I get iOS to play notification sound? Thank you in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source