Recognising iPhone Silent Mode - iphone

I would like to stop my application playing a sound if the user has switched the iPhone to silent mode. Where can I read that the phone is in silent mode? Is there some flag I can query? I noticed that some applications ignore the silent mode and some not, while I would have expected all apps to respect that silent is silent !!
Any hints or input would be greatly appreciated.
Thanks
Al

The Human Interface Guidelines published by Apple describes what is the ideal behavior for Apps to follow for Ring/Silent switch. So you may not need to disable audio if the user explicitly played that audio clip despite on silent mode.
The Ring/Silent Switch—What Users Expect
Users use the Ring/Silent switch to silence their devices when they want to:
Avoid being interrupted by unexpected
sounds, such as Phone ringtones and
incoming message sounds.
Avoid hearing sounds that are the
byproducts of user actions, such as
keyboard or other feedback sounds,
incidental sounds, or application
startup sounds.
Avoid hearing game sounds, including
incidental sounds and soundtracks,
that are not essential to using the
game.
For example, in a theater users switch their devices to silent to avoid bothering other people in the theater. In this situation, users still want to be able to use applications on their devices, but they don’t want to be surprised by sounds they don’t expect or explicitly request, such as ringtones or new message sounds.
However, the Ring/Silent switch does not silence sounds that result from user actions that are solely and explicitly intended to produce sound. For example:
Media playback in a media-only
application is not silenced by the
Ring/Silent switch because the media
playback was explicitly requested by
the user.
A Clock alarm is not silenced by the
Ring/Silent switch because the alarm
was explicitly set by the user.
A sound clip in a language-learning
application is not silenced by the
Ring/Silent switch because the user
took explicit action to hear it.
Conversation in an audio chat
application is not silenced by the
Ring/Silent switch because the user
started such an application for the
sole purpose of having an audio chat.
This behavior follows the principle of user control because it is up to the user, not the device, to decide whether it's appropriate to hear sounds the user explicitly requests.

You need to set the appropriate Audio Session Category.
You tell iPhone OS your application’s
audio intentions by designating a
category for your audio session.
For more detail see - Configuring the Audio Session

If the iPhone is silent, why stop playing a sound?
Or, does silent mode just not play certain sounds? I don't have an iPhone (iPod Touch) so I'm not sure.

Related

iPhone:don't want to exit game while ring/silent switch turns on from turns off mode

I am working on app in which audio file playing very vital role.
for playing audio file I am using AVaudioPlayer in my app.
but one problem is suppose device is in silent mode and user starts running the app
and suppose he/she turns on silent/ring switch in the middle of the app.
right now he/she must exit the game but I want such kind of functionality in
which He/she should not exit the app and in the middle of the app user should be
able to hear the sound when he turns on the ring/silent switch from the device.
iOS apps have the ability to play music in the background whether they be games or not, since multitasking was introduced in iOS.
See the following tutorial.
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_background-audio/
Whether its legit for a game to do this I seriously question. But thats your call.

Running the code when application is in the background or device is locked

I have a piece of code wherein I make a server call and based on the response I play a sound. Now, this does not work when my application is in background or my devicei is locked.
Is there any way we can execute this piece of code (Server call and response handling) even if app is in background or device is locked?
There is no general solution, which is by design. (Apple does not want you to have a potentially CPU- and power-intensive process running in the background and degrading user experience.)
There are a few limited-case options available:
You said you want to play a sound. If by this you mean "play music" or some such streaming, there is an audio background task that your application can register to perform. Note that you must actually be streaming audio; Apple rightfully frowns upon apps that try to use this approach to circumvent the general-case prohibition and will reject your App Store submission accordingly.
You can invert your scenario and have the server send a push notification through the Apple Push Notification service. Depending on the user's settings, an alert, badge, or sound can result. This might be the best fit for you if you aren't streaming audio.
If what you are really intending to do is, say, finish an upload or download (and the sound is a completion notification), you can request some additional time to finish that task after the app is nominally backgrounded or the device locked. Use -[UIApplication beginBackgroundTaskWithExpirationHandler:] from within the appropriate UIApplicationDelegate methods to register such a task. Note that you have a limited (but appreciable) amount of time to finish your task, and I don't think you can play media in this mode.

Disable silent mode on iPhone?

How do you disable the user from turning the phone on silent? (switching the switch on the top left of the phone?)
I want my app to always play sound no matter what the state of that switch is. Is this possible?
Thanks in advance...
Please search stackoverflow or the web for similar questions before posting a new one, this question has already been covered:
Play sound on iPhone even in silent mode
iphone, how to play sound even in silent or mute mode?
Be careful about overriding the silent mode switch and playing audio. Apple may not like you doing this, depending on the context; if they don't like it, you will fail app review. Is there a good reason to play audio when in silent mode in the context of your app?
Here’s what I have done that works great!
Set all your contacts Emergency By Pass OFF! Then decide who should break through by turning the Emergency By Pass ON to those important calls you simply can’t miss; Family members like Mom and Dad.
Now your all set to use he Silent switch.

Best practice for volume control iOS?

Hardware Volume Control
I'm trying to understand what is best practice for apps that are mostly silent but occasionally produce sound. Such apps can take advantage of the side volume control on iOS devices and avoid the need to design in a NSVolume control widget, which I believe is not as convenient as the hardware side volume control. The approach would apply to apps like MapQuest 4 mobile where you get occasional audio prompts that blend well with other music players (using audio ducking) but are silent for the most part. I'm wondering how others are addressing this same issue.
I have developed such a system that works rather nicely. In my approach I query the audio APIs to determine if other music is playing (iPod, AOL Radio, Pandora, etc.) then start an audio session only if no other audio is playing. This ties the hardware side volume control to the app instead of the ringer (for iPhones). The challenge comes when you go to the background. My approach kills (deactivates) the session in the background only if the app is not using audio. If there is audio playing the session is deactivated at the conclusion of the playback.
The idea behind killing the playback is to restore the user's ability to adjust the ringer volume to their liking should my app continue to run in the background.
This question originates from issues I faced when developing the voice navigation feature on MapQuest 4 mobile on iOS in 2008-2009. In this app we wanted the side volume switch to control the volume of the turn advice at all times while the app was running. I later realized that I could not control my ringer volume after arriving at my destination and sending the app to the background. This was years ago but I believe the app was continuing to run in the background which lead to the problem. It is an interesting case, when the user is navigating but sends the app to the background should you continue the audio session? Is is more likely that the user would like to change the app volume or the ringer volume while the app runs in the background?
My general use case (when I posted this question) involved navigating in the background while running another app in the foreground (commonly a music player). However it is also common for the navigation app to be sent to the background while the user sits on the home screen. This is when it would make sense to deactivate the audio session.
It is not as straight forward as it seems but my approach works for most cases. Still I am wondering if there are other more viable solutions to the problem. What are other people doing? Would it make more sense to just include the volume control in a view that auto slides in/out of place? Are there things that I have not considered? How have you approached the problem? Do you have any general suggestions?

How to Turn on Music (ipod library) on iPhone?

I already know how to keep play music at background in my app.
I don't want to know that.
I want this.
how to Automatically turn on ipot music in background & sleep mode at custom time.
it's thought impossible to me.
but that's possible. and no jail break.
i wanna know that. please help me.
Take a look at the following background task guide from the iOS docs
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html
There are restrictions on what can be carried out in the background. Certain apps that support audio, location, and voip are allowed to run in background using the UIBackgroundModes key. With the audio background task, it will not be suspended until the audio session stops.
It seems that you don't want to initiate a session until a certain time. You could potentially look at beginBackgroundTaskWithExpirationHandler: .
Also if you are looking for a timed alarm, you can always attach a different tone to a local notification.
As far as I am aware, there is no "out-of-the-box" way to do what your asking.