Closed nimdanet closed 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.
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.
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