How to programmatically silence the ringer or change the ringer tone on iOS5
Asked Answered
P

2

5

Is there a way to reduce the volume of the ringer or change the ringer tone on iOS5?

I checked out the Celestial framework, but can't instantiate AVSystemController. :-(

I don't care if this get's the app rejected in the AppStore as it will never be submitted.

Polyhydric answered 16/2, 2012 at 23:29 Comment(0)
K
9

Yes. Use AVSystemController. You don't instantiate it. It's a singleton.

http://code.google.com/p/iphone-dev/source/browse/trunk/include/include/Celestial/AVSystemController.h?r=136

[[AVSystemController sharedAVSystemController] setVolumeTo:10.0 forCategory:@"Ringtone"];
Kudos answered 17/2, 2012 at 2:47 Comment(8)
Could you provide an example, please?Polyhydric
I tried including the file you linked, but I get the following error: Undefined symbols for architecture i386: "_OBJC_CLASS_$_AVSystemController", referenced from: objc-class-ref in FRRViewController.o ld: symbol(s) not found for architecture i386 Besides, there's not setVolumeTo:forCategory: method in the linked file.Polyhydric
It simply may not exist in the simulator — have you tested on device? You could use [[NSClassFromString(@"AVSystemController") sharedAVSystemController]... to produce code that works either way if that's the cause.Cornstalk
You have to link against the Celestial framework. Or you can do what Tommy suggested if you want to avoid linking against it.Kudos
And setVolumeTo:forCategory: does exist. The file I linked to is old. Maybe from iOS 3. setVolumeTo:forCategory: is available in iOS 4 and 5 I think.Kudos
@tommy I had already tried what you suggested, but [[NSClassFromString(@"AVSystemController") sharedAVSystemController] always returns nil, both on the simulator and the device (iPhone 4 on iOS 5).Polyhydric
@Fernando I have used that exact code, and it works fine. Also, it won't work on the simulator, only an actual device.Kudos
This approach is working well for me. Where can I find a list of supported categories though? So far I'm only aware of "Ringtone" and "UserInterfaceSoundEffects".Cooke
C
0

This might be what you are looking for: Override ringer volume in iPhone apps

Basically, you set the volume using AVAudioPlayer on the -(void)viewDidLoad method of the view you are displaying on

Campbellite answered 21/2, 2012 at 23:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.