Invoke the application to play a music on receiving a push in iOS - 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

Related

Open an app on battery notification

I'm looking for a way to open (or display a notification from) an iphone app when a low battery level notification occurs. Is it possible to perform it if my app is running in background ? I found that an app can't refresh after some minutes in background, but I wonder how many apps can display notifications by their own without being opened.
Thanks.

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).

IOS App and Background

I have a music signal processor app I want to publish and it needs to run in the back ground. I used to Info-plist to do so with UIBackgroundModes. It runs on IOS7 or less, and the problem I am having is once the phone locks and the app goes into the background I can't get it to come out of the background and its keeps running with the red banner at the top. Some of this I have learned as I go, but I have noticed some run on a timer, but I want mine, since its a music processor to keep going until the phone either unlocks or whatever interrupted it stops.
The app is basically a stomp box used with iRig. If that helps.
Thanks
Can you clarify about what you mean when the phone locks, the app goes into the background and yo can't get it to come out of the background? Are you saying like the app is playing music while the app is locked?

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.

UILocalNotification how to call certain method if application is in background

I am creating player application, which is playing audio streams through internet. I want to add alarm functionality in my app - in particular time my player begins to play audio stream, I am trying to use UILocalNotification mechanism. But I've difficulties with it when my application in background mode, I can't call 'play' method, when notification is receiced (can't without user interaction). May be it is impossible?
But I bought this application:
http://itunes.apple.com/us/app/radio-alarm-clock-mp3-radio/id380271167?mt=8
And it seems like radio can start playing when local notification is received. Alarm can start playing radio when my app is in background mode.
Earlier I was trying to use NSTimer for this, but when my app goes to background, timer stops. If I use beginBackgroundTaskWithExpirationHandler: it works only 10 minutes. My app has special flag in plist, what is is audio application, and can playing music in background. In this case timers are working. But if I stop playing and go to background, timer is not working.
When I use \Radio Alarm Clock' application, I hear 'white noise' from dinamic, when music in not playing. May be it is the secret of this application?
Can you help me with my problem? Thanks.
maybe it's too late.
I had a look to the app you've mentioned at http://itunes.apple.com/us/app/radio-alarm-clock-mp3-radio/id380271167?mt=8 and yes, I think you are absolutely right, the only way to achieve that the application remains active while in background is to play a fake sound while it is in the background, which should be prohibited by Apple.
I've also seen that they don't use the remote iPod control, and this was strange at a first look.
At the end my opinion is that they do the following:
Avoid the call to beginReceivingRemoteControlEvents which allows to activate the iPod controls while in background (in fact they don't have it)
In this way, the status bar doesn't show the play icon while
the app plays audio
When the app goes in background, it probably plays a no sound periodically (once every 10 secs for example), in this way the app remains active
I saw that they also avoided to manage interruptions, for example in case another app is in foreground and plays music. Again Apple should have rejected the app for that reason, cos it is against the rules to follow while in background, but maybe they didn't see it during the acceptance tests.
So my interpretation is that they have intentionally missed to activate the iPod controls, just to avoid to show the play icon in the status bar while in background. In this way, the users are unaware that the app is active and is doing something strange after they close it.
In addition you can see that the app doesn't interrupt when another app plays in foreground a sound or audio, because otherwise they risk that the app doesn't restart on time when the alarm shpould fire.
That's just my idea of how they do that, and I think this is the only way for an audio app on iOS to remain active while it is in background and is supposed to be halted (well, in case Apple doesn't see the trick).
Have you tried adding this to appdelegate.m
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
// Call your method in here.
}
if you have can you add code for us to see what your doing.

Resources