I found out I need to put my custom notification file to xcode project but I am not sure where to..
where should I put my notification sound?
The file has to be named beep.wav and placed right in the www folder.
From the Cordova Docs:
There is no native beep API for iPhone.
Cordova implements beep by playing an audio file via the
media API.
The user must provide a file with the desired beep tone.
This file must be less than 30 seconds long, located in the www/
root, and must be named beep.wav.
Custom notification sound can be named anything you like and put the .wav file into your Resources folder in the xcode project. Then specify the name in the payload of your push notification.
Related
I am using flutter_local_notifications 9.4.1 in my flutter mobile application
I am deploying successfully to Android and iOS 14.2
My use case is simple - to provide a local notification with a sound when a specific task has completed.
Android - everything works fine - my mp3 sound plays when the notification appears just as I want. Perfect.
iOS - I have everything working except for sound. I have added a custom sound (a CAF file converted from a .AIF file, using the Apple recommended procedure ... afconvert). I added the sound file to the Flutter project the correct way - by using XCode to include it into the top level folder with the target ticked. In my flutter code, I already have the modification to the appDelegate.swift, and in the IOSNotificationDetails I have ensured that presentSound is true and presentAlert is true. I am also specifying sound: 'mysound.caf'. But actually even if I don't specify a custom sound, according to the documentation, the default sound will be used. But no sound occurs, default or otherwise.
On the iPhone device, I have checked silent mode is off, I have checked the app permissions - everything set as it should be - sound is enabled, notifications are enabled. I have even copied the CAF file manually to the iOS device to be sure it plays and that I can hear it! I have no build errors or run-time errors. So I must be missing something.
I don't know of a way to check that the sound file is actually deployed to the device - is this possible?
Is there something in the setup or deployment process I have missed? I have not posted code up because I have spent hours comparing my code to the documentation and finding no differences. I am hoping someone has experienced this and found an undocumented step.
I want to use my own sound in push notification in iOS platform of Flutter. Since I have no experience in iOS development, I am struggling with it.
In my app settings there are 3 notification sound options, so that user can choose notification sound. I have already implemented local_notifications package and although I am getting notifications in my app, I couldn't find how to use custom sound in push notification for iOS platform.
You should replace this default given sound name to your sound name.
var iOSPlatformChannelSpecifics = IOSNotificationDetails(sound: 'slow_spring_board.aiff'); //put your own sound text here
(Before this, your sounds should be added to your project using Xcode)
Here is the link how to add custom sound to your project for iOS devices using Xcode: https://medium.com/#dmennis/the-3-ps-to-custom-alert-sounds-in-ios-push-notifications-9ea2a2956c11
Note: Sound duration should be less than 30 seconds otherwise it will not work
I have not found a definite answer to this. This SO article from 2012 does not work anymore.
So far I have included audio in the UIBackgroundModes array in my Info.plist file.
Furthermore I installed the cordova-plugin-media plugin (version 3.0.1). But the music still fades out when I press the home button. What am I missing?
So my problem was, that I didn't see an Info.plist file and simply created my own.
Under cordova the file is called <app_name>-Info.plist and located in the Resources folder. Either way it can also be accessed under the Info tab when selecting the project target.
So after adding audio to UIBackgroundModes to the correct file even the simple HTML5 <audio> tag continues to play in background. Yay!
I found this project on GitHub: iOS Sounds and Ringtones
Is there a way to play one of those sounds for localNotification.soundName?
So I got the string for "/Library/RingtonesApex.m4r"
But it still plays the default notification sound.
UILocalNotification accepts only a sound file name, not a file path. And the docs for soundName explain that this file must be "...in the app’s main bundle...". Getting the path to a system sound file is not useful with UILocalNotification because that file is not in your app's main bundle, and because you can't tell UILocalNotification to look somewhere else.
Surely possible , you need just to move the custom sound you need to this path :
Library/Sounds ,,,by default Sounds folder is not under library ,so you need to create it , then copy any custom sound file (either after downloading to documents then copy or copying system sound ) to this directory as i said Library/Sounds . According to Apple , Sound files should be in bundle (in case get shipped with app) or in ONLY this directory Library/Sounds . You can assign only sound file name with any extension to the sound name property in local notification before iOS 10 and after iOS 10 you can assign ti to content sound name constructor . I tried it several times before and both worked for local and remote notification by either playing sound from remote server or system sound . If you need any help putting this to work in any swift versions or objective-c you're welcome .
Set for your UILocalNotification soundName property
UILocalNotification *localNoti = [UILocalNotification alloc] init];
localNoti.soundName = #"your sound with file format (exmpl.m4r)";
And make sure that your sound no longer than 30 sec. It's a limit of sound length
Hope this help
I wrote the repo you linked to in the original post.
Unfortunately, you cannot refer to the path of the sound in a localNotification. You have to have the file in the app bundle (i.e. a .MP3 file attached to your app) to use it as a custom sound.
I've added a custom sound to my app but it doesn't get played when a push arrives.
I've no idea why not, I can't see anything different from what I have done and there are so few steps involved.
1) The sound file is a valid audio file which is audible (I can even click and play it within Xcode).
2) The sound file is present in the app's bundle:
3) The sound file name is specified with the exact name and case in the push payload:
{"aps":{"alert":"Test","badge":0,"sound":"PyngNotification.caf"}}
4) I've tried specifying the name without the extension, just as "PyngNotification".
5) The push arrives and is displayed but the custom sound isn't played.
6) The phone makes the same noise regardless of if the push content contains a sound of "PyngNotification.caf", "default" or "". Its a short buzz type of sound.
7) Sounds are not disabled on the phone, nor for pushes for the app.
8) The app is registering for UIRemoteNotificationTypeSound (if iOS8). (The app displays Sounds as one of the permitted types if viewed via the control panel).
9) I have more than one phone, one with iOS8, one with iOS7. The sounds plays on neither of them.
10) The sound is under 30 seconds.
11) The sound was ma4 and converted to caf using afconvert.
I can't see any steps I've left out, nor anything that is incorrect.
Anybody have any ideas?
Tap on the sound file that isn't working in Xcode. Look at the file inspector on the right and make sure the "Target Membership" option is checked.
The steps which you provided are pretty much everything I had, except background modes setup. I had to put check on the "Audio, Airplay, and Picture in Picture" mode from the Capabilities > Background Modes. Hope it helps.
Acc. to Apple's Documentation
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6
Preparing Custom Alert Sounds
For remote notifications in iOS, you can specify a custom sound that iOS plays when it presents a local or remote notification for an app. The sound files must be in the main bundle of the client app.
Custom alert sounds are played by the iOS system-sound facility, so they must be in one of the following audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
You can package the audio data in an aiff, wav, or caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle.
You may use the afconvert tool to convert sounds. For example, to convert the 16-bit linear PCM system sound Submarine.aiff to IMA4 audio in a CAF file, use the following command in the Terminal app:
afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d
ima4 -f caff -v
You can inspect a sound to determine its data format by opening it in QuickTime Player and choosing Show Movie Inspector from the Movie menu.
Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.