Reputation: 2314
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.
Upvotes: 5
Views: 1440
Reputation: 16116
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 :
References:
Upvotes: 7