Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom notification sound in android and ios #61

Merged
merged 4 commits into from
Aug 8, 2024

Conversation

mirzemehdi
Copy link
Owner

@mirzemehdi mirzemehdi commented Aug 8, 2024

Solves #34

@mirzemehdi mirzemehdi linked an issue Aug 8, 2024 that may be closed by this pull request
@mirzemehdi mirzemehdi marked this pull request as ready for review August 8, 2024 13:18
@mirzemehdi mirzemehdi merged commit cc6361c into rel_v1.2.1 Aug 8, 2024
@mirzemehdi mirzemehdi deleted the feat/notification_sound branch August 8, 2024 13:19
@mirzemehdi
Copy link
Owner Author

Add custom notification sound when initializing the library as below:

Android:

@param soundUri - Custom Notification sound, uri should be converted to String. Default value is null, if null default notification sound will be played. For custom notification sound put notification sound in res/raw directory. See how it is used in sample app: 3708ea8

val customNotificationSound =
        Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + "com.mmk.kmpnotifier.sample" + "/" + R.raw.custom_notification_sound)
    NotifierManager.initialize(
        configuration = NotificationPlatformConfiguration.Android(
            notificationIconResId = R.drawable.ic_launcher_foreground,
            showPushNotification = true,
            notificationChannelData = NotificationPlatformConfiguration.Android.NotificationChannelData(
                soundUri = customNotificationSound.toString()
            )
        )
    )

iOS:

@param notificationSoundName - Custom notification sound name. Default value is null. If set null, default notification sound will be played. For cusotm notification sound, place the file in the Resources directory of your iOS target. Ensure the file is added to your target's "Build Phases" under "Copy Bundle Resources". See how it is used in sample app: 4b2a90d

NotifierManager.initialize(
        NotificationPlatformConfiguration.Ios(
            showPushNotification = true,
            askNotificationPermissionOnStart = true,
            notificationSoundName = "custom_notification_sound.wav"
        )
    )

@Endless-Lemniscate
Copy link

Is it working for push notifications too or only for simple notifications?

@giagiac
Copy link

giagiac commented Sep 27, 2024

In my case it works only for simple notifications (IOs)... not from push!! Probably i miss something... this calls for a new investigation 🧐

after the investigation 😅

this is the right fcm payload - in this case also with IOs (PUSH notification) works.

{
    "message": {
        "token": "...",
        "notification": {
            "body": "BODY -> {{NOW}}",
            "title": "TITLE -> {{NOW}}"
        },
        "apns": {
            "headers": {
                "apns-priority": "10"
            },
            "payload": {
                "aps": {
                    "sound": "default"
                }
            }
        }
    }
}

or

"sound": "custom_notification_sound.wav"

@mirzemehdi thanks 4 y job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possibility to add sound to notification
3 participants