How to play background push notification sound - ios

I'm working on an app in which, upon receiving a push notification while in the background, should play a continuous sound until the app is opened.
Also, if the app is opened by clicking on the app icon, it should load push data.
How can I do this?

Related

Handle push notification when app is running and notification tray is opened

While trying to implement FCM in my iOS app, I came across this issue. I have my app opened, at the same time I slide down the Notification tray of my device. When I send a push notification, my application state prints as INACTIVE (which is correct since the tray comes in foreground, leaving my app in the background)
I am loading a URL on notification tap, hence when user slides up the tray, the url is directly loaded and no notification is displayed in the tray.
In this scenario, I wish to display notification in the tray and open URL only when the user taps on the notification. Is there any way to detect if the Notification tray is visible over my app specifically?
you can use Third party library : https://github.com/bryx-inc/BRYXBanner or you can show alert by handling if app is in foreground or inactive state in notification recieving delegate.

Push Notifications for iOS while in the background

My app is receiving a notification and my problem is that when I received one or more notifications in the background and when i click the app icon to bring me in my app foreground then the notification message(s) doesn't able to display in the foreground it will only works if I click the pop up message in notification center not the icon.
You will not get remote push notification data on launch of app after tapping icon. You can only parse push notification body only on tap of notification alert.
So if you want to do any MUST NEED operation for such notifications there is only way is to introduce server in between. So you can use any web service for it and this will be called every time your app launches or comes to foreground. Call that API on background and do the needful you want.

ios play continues sound when app receive push notification

Currently i am working on app in which i want to play continues sound when app receives push notification. as i know apple allow to play custom sound of length of 30 sec here is link..
but in well known app it plays continues sound in driver side when app is in back ground and driver receives order.
and another issue is of when my app is in back ground and receives push notification Rather clicking on notification if i open app by pressing app icon it does not show me data of push. it is not possible to load data when press on app icon here is link
iOS Push notification issue
but same thing is done in well known app
With iOS 7+, use application:didReceiveRemoteNotification:fetchCompletionHandler:, which is called even if your app is in the background. iOS will even launch your app in the background if it's not already running, but if the user force quits the app, it will not be re-launched. If you enable the remote-notification background mode, you can run app code when the notification arrives. If you include the audio background mode, you could initiate a sound that continues to play while app is in background.
For second question, typically, your app should query a server for updates if it's launched directly. However, you could leverage a remote notification as above, which you'd get in most cases (except if the app were force quit).

How to stop the LocalNotificationSound when application is opening from Device Locking screen

In my application iam using UILocalNotifications, and for that notification iam setting 30 sec audio file.
Notification fired if device is UnLock state and my app is in background mode then if i click on notification bar then my app is open and notification sound is stopping. This scanario is fine.
Notification fired if device is locke state and my app is in background mode then if i drag the notification then my app is open and notification sound is not stopping. In this scanario notification sound is continuesly playing upto 30 sec.
I need to stop the notification sound when app is open.
Please help me for implementing this functionality.
Thanks in advance.
You can't, since the sound is played by iOS and not your app. Thus you have no control over it.

Invoke the application to play a music on receiving a push in iOS

I implemented Push notifications in iOS. I want my application to play a music (about 15sec) when I send a push message. I am currently getting the push message, and the music is being played only if the app is in the foreground.
If the app is in the background, it shows up a notification, and when i tap it, it then plays the music.
But how do I get the functionality of automatically playing the music? I think this can be done because, in iOS, Audio apps can run in the background. So I just want the music to be played when the app goes to background, and it receives a push.
Can anyone help me with this please?
Thanks,
Nithin
Yes, there are two ways to do this.
The traditional way before iOS 7 is to register for audio playing background mode and play a silent sound forever, this will keep your app running in the background for a long time until the user kills it, or it is killed due to low memory.
This way has many drawbacks, the user must launch your app once so that you can start playing the sound and every time the iPhone is shut off, the user need to relaunch your app when he turn on the iPhone.
Also this will consume a lot of battery. 20%-30% a day for an iPhone 5.
The new way after iOS 7.0 is to exploit background fetch and remote notification, you can play your sound while performing a background fetch, which has a 30 seconds running time. Also you can trigger a background fetch with a push notification.
This is an article about background fetch and push notification http://www.objc.io/issue-5/multitasking.html

Resources