Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to shut off ring tones on the phone (mute the iPhone) via code in iOS 7?

Is there any way to shut off ring tones on the phone (mute the iPhone) via code in iOS 7?

There is one app in the AppStore that I found which has logic that shuts off a phones ringer even when the iPhone ringer switch is set to On. https://itunes.apple.com/us/app/silentalert/id506092189?mt=8

Some piece of code or some reference are highly appreciated. I went through many Stack-overflow post without much success.

like image 407
Adarsh V C Avatar asked Mar 10 '14 07:03

Adarsh V C


1 Answers

First, can you specify what you have already tried and you have not been able to get working ?

Also see this related and possibly duplicate StackOverflow Question. Which says it isn't possible and then mentions the private APIs which the Apple AppStore won't approve.

For more information on the private APIs see this StackOverflow Question.

Specifically you would need to call toggleActiveCategoryMuted from the Celestial Private API or setMuted in AVController, but this would most likely be rejected by Apple in terms of AppStore submission.

Based on reading the API documentation I believe the way the referenced Application works is by setting the AVAudioSessionCategory to AVAudioSessionCategoryAudioProcessing and making itself the active session.

If this doesn't continue silence when the application becomes background and you want to request more time, see this StackOverflow Question. Alternatively, see something like this code example and supporting blogpost which plays silent sound repeatedly. Note Apple app store review also frowns on this method apparently. The code is actually a newer fork which is supposed to work better on new iOS versions.

It also has all the handling for being a background application, playing music / silence in the background, and handling interruptions. The usage of the Location Services is probably so that it can use the (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations to trigger application relaunching using region monitoring or the significant-change location service.

Code examples of the concepts are linked below :

  • Example music application that plays music in the background. I suggest changing the ession category to AVAudioSessionCategoryAudioProcessing and having a toggle which switches it back to AVAudioSessionCategoryPlayback and seeing what happens.
  • Example of changing just the AVAudioSessionCategory
  • Example of changing the AVAudioSessionCategory and setting the active session
  • Session setup and interuption handling

References:

  • Playing and Recording Background Audio
  • Audio Session - Ensuring audio playback continues when screen is locked
  • Audio Session Programming Guide
  • AVAudio Session Class Reference
  • StackOverflow Answer to a different question which states that if not reset , no audio is played
like image 53
Appleman1234 Avatar answered Nov 09 '22 15:11

Appleman1234