Is there a way to programmatically override remote push notification sounds using Swift? - ios

I have a Swift iOS8+ app that receives remote push notifications from a 3rd party server over which I have no control.
That server sends push notifications as JSONs with the usual "alert" and "badge", but does not send the "sound". Consequently, my app plays the default alert sound for push notifications.
Is there any way to programmatically override the sound, so that I can play my own, custom remote push notification alert sound? Or even programmatically mute the sound? Remember, I cannot force the sending server to change the push notification payload to include a different sound.
I began by placing the sound file (ding.aiff) in my main bundle, but there seems to be no way of using that file in my app to play it instead of the default alert sound.
Does anyone know of a way using Swift 2+ on iOS8+ that can override or mute the remote push notification alert sound?
(If this is not possible - perhaps Apple is paranoid over music copyright - is there a way to mute the sound programmatically?)

Related

Banner calling notification like WhatsApp video call in iOS

My app is a VOIP app. and it was working fine before apple restricted to trigger CallKit as soon as VOIP is received.
Before this limitation i was receiving the call alert as VOIP and was repeatedly creating a local notification which was achieving the goal.
To cater the case i tried the following:
Silent notifications:
These works fine only when the app is in foreground. In background i receive a silent push but can't play the sound using
AudioServicesCreateSystemSoundID(url as CFURL, &mySound);
AudioServicesPlaySystemSound(mySound);
AudioServicesPlaySystemSoundWithCompletion(mySound, {
AudioServicesDisposeSystemSoundID(self.mySound);
});
also the silent push is not received when the app is in killed state.
Notification Service Extension:
I have also tried to trigger my repeated local notification in this extension but was not able to do that as the notification extension scope is not in the app.
Is there any way to trigger a function of application when notification extension is triggered irrespective of what is the state of app e.g (killed, background, foreground, suspended)?
Any help will be appreciated to move on from here.
Need to achieve this repeated ringer

Stop to play Push Notification sound as I receive PushNotification Payload, (or When DidreceiveNotification method of App Delegate is Called)

I am new in iOS development, and I am working on an iOS app in which some options are available for user to get pushNotification, such as users can select "Do not Disturb", "AnyTime" "time b/w"...something like this. So If user choose "Do not Disturb" then I do not have to play sound and alert. So please give me solution of that.Is this possible or not in iOS App development. Please tell me.
Thanks in advance...
If you don't require sound for the push notification, Don't give sound object in push payload.
If the user has chosen "Do not Disturb", indicate the server sending push notification to remove sound from the payload.
{
"aps":{"alert":"Hello","category":"your_category_key"}
}
Other wise include sound.
{
"aps":{"alert":"Hello","sound":"default","category":"your_category_key"}
}

iOS remote notification:How to play the alert sound customed by user in iOS client while not decide by the apns argument ('sound')

iOS remote notification:How to play the alert sound customed by user in iOS client while not decide by the apns argument ('sound') ?
I don't want to tell the backend which sound file was chosen by the user
Can I convert the remote notification to local notification?

Changing push notification sound to a file not in the app bundle?

Is is possible for a user to record a new sound to be used as the sound for the push notifications they receive from the app? In other words, is it possible to dynamically change the push notification sound using sound files uploaded externally, or do they have to be already located in the app bundle?
From the Push notifications programming guide:
For remote notifications in iOS, you can specify a custom sound that iOS plays when it presents a local or remote notification for an application. The sound files must be in the main bundle of the client application.
So I would think that it's not possible, sorry.
The notifications will often be processed by the system while the app is closed, so I don't think there is a way to configure its behaviour beyond the basic features.

How don't allow iOS to start application when specific type of push notification arrives?

I want PHP server send to my iOS application two types of push notifications:
New income message. For this push I want iOS start my application if it was suspended, show badge, play sound, etc.
New friend request. I don't want this push to start my application and I only want to handle if the app is in the foreground.
How can I achieve this? How can I handle different push notifications differently?
I'm not sure if it will work, but you should try for your 2nd scenario to send a notification that contains only custom properties. In this case there will be no alert to display, sound to play nor badge to update, so I think this notification will only reach your app if it's already running.
For the 1st scenario, send a notification with pre-defined properties (alert, sound, badge).
Application-side handling for remote notifications should start with the method in the application delegate protocol application:didReceiveRemoteNotification:.
However, in order to avoid the application launching in the first place, you need to make sure the PHP server crafted notification doesn't offer the option to launch the application.
See the documentation on the Apple Push Notification Service here:
http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9
In particular, you want to focus on the content of the aps dictionary as documented in The Notification Payload section. The aps dictionary received can badge your application's icon without opening the app at all.

Resources