Agasper / unity-android-notifications

Unity3D Plugin for Android local notifications with example project
Other
555 stars 184 forks source link

iOS default sound #124

Closed nimdanet closed 5 years ago

nimdanet commented 5 years ago

I'm having trouble with iOS default sound. If I don't pass any soundName as parameter, notification do appear but don't play any sound (regardless if app is on foreground or background). When I was writing my own code I had to manually call soundName = UnityEngine.iOS.LocalNotification.defaultSoundName but in your code this does not seems to work. I changed your line to this: notification.soundName = (soundName != null) ? soundName : UnityEngine.iOS.LocalNotification.defaultSoundName; but my iphone refuse to play any sound. Custom sound plays nice though. Do you know how can I fix this?

Unity 2018.1.9f1 Xcode 10.1 iPhone 7 iOS 12.1.2

nimdanet commented 5 years ago

More info:

I changed all your iOS code from SendNotification() to this:


UnityEngine.iOS.LocalNotification notification = new UnityEngine.iOS.LocalNotification();
notification.alertBody = message;
notification.fireDate = DateTime.UtcNow.AddMilliseconds(delayMs);
notification.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;
UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification);

return id;

It doesn't have any of your usabilities but it do fire notifications with default sound. I made this to make sure it was not a device-related problem.

nimdanet commented 5 years ago

So I edited directly LocalNotifications.m and it worked. I also edited so when you send "sound: false" it doesn't display any sound. Basically on scheduleNotification I changed this:

if (notifStruct->soundName) {
            notification.soundName = findSoundResourceForName([NSString stringWithUTF8String:notifStruct->soundName]);
        }

to this:

if(notifStruct->sound) {
        if (notifStruct->soundName) {
            notification.soundName = findSoundResourceForName([NSString stringWithUTF8String:notifStruct->soundName]);
        }
        else {
            notification.soundName = UILocalNotificationDefaultSoundName;
        }
    }

I'm attaching to modified LocalNotifications.m if anyone wants it.

LocalNotifications.m.zip