Is there any alternate solution to mute ringer programmatically? - iphone

I'm working on an iphone application which used to mute the phone ringer programmatically.Currently I'm using celestial.framework to mute,but I come across that the apple will reject using private framework.Please anybody give right solution to achieve it.I'm new to iOS development.Thanks
Class avSystemControllerClass = NSClassFromString(#"AVSystemController");
NSString *soundCategory = #"Ringtone";
float newVolumeLevel = 0.0;

Related

How to disable iOS System Sounds

I am working on an iPad app that connects with an accessory that plays sound. When the iPad is connected to the accessory, I would like to mute all system sounds but allow other sounds (iPod).
Part of the reason for this is that the accessory is such that it is intended to be used during a live performance. Clearly it would be annoying to have e-mail, alert, or any other system sound running through and amplified (crazy loud).
I have looked at using AVAudioSession (read Audio Sessions to learn more) and tried all of the AudioSessionCategories. None of these categories will mute the system sound, instead it will only allow you to mute application sounds (iPod) - not useful for my purposes.
I also found docs on "System Sound Services", but this only allows you to play system sounds. There is no api here to disable system sounds while your app is running.
A final note, we have made it easy to adjust the iPad level (volume) by including the MPVolumeView, but we expect the user to want to play iPod music. If while playing iPod music (or music from another app) and an e-mail comes through, you'd be amazed how LOUD / ANNOYING that e-mail suddenly becomes when going through our accessory. It's even possible it could damage equipment. :D
It is possible to change the system sounds, which turns out to be the ringer btw, using the AVSystemController. However, AVSystemController exists in the private Celestial framework. Since this framework is referenced by UIKit, it is still possible to use this class without directly referencing it.
Apple prohibits using private API's, so that alone makes this a bad idea. Given my circumstance, I think they may make an exception, BUT I will likely abandon this course since after taking it I realized that it didn't fix my problem. It does indeed mute the sounds, but as soon as I plug in to my accessory, the system sounds come out at max volume even though the ringer volume is set to 0. This leads me to believe the answer to solving my problem is in the MFI documentation.
Anyhow, here is how to change the ringer using private framework / api (which will get your app rejected without some kind of special permission).
short answer:
[[AVSystemController sharedAVSystemController] setVolumeTo:0 forCategory:#"Ringtone"];
answer without having to directly reference Celestial frameork / AVSystemController.h:
- (void) setSystemVolumeLevelTo:(float)newVolumeLevel
{
Class avSystemControllerClass = NSClassFromString(#"AVSystemController");
id avSystemControllerInstance = [avSystemControllerClass performSelector:#selector(sharedAVSystemController)];
NSString *soundCategory = #"Ringtone";
NSInvocation *volumeInvocation = [NSInvocation invocationWithMethodSignature:
[avSystemControllerClass instanceMethodSignatureForSelector:
#selector(setVolumeTo:forCategory:)]];
[volumeInvocation setTarget:avSystemControllerInstance];
[volumeInvocation setSelector:#selector(setVolumeTo:forCategory:)];
[volumeInvocation setArgument:&newVolumeLevel atIndex:2];
[volumeInvocation setArgument:&soundCategory atIndex:3];
[volumeInvocation invoke];
}
Using MediaPlayer framework, we can set the level of SYSTEM sound
[[MPMusicPlayerController applicationMusicPlayer] setVolume:0];
Best you can do is encourage your users to go into airplane mode.

Turn off display in iPhone OS (iOS)

is there a way to programmatically turn off the display in iOS? Not just turning brightness down, but off like the way the Phone App does. I am happy to use private API, since this is for personal use.
Thanks!
You can turn off the display by enabling the proximity monitoring. It will automatically turn off the screen, like in the Phone app, by placing the phone near your ears or by placing a finger over the IR sensor at the top of the phone.
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
You can do this, (obviously, using Private APIs of course) :
on iOS5:
#include <stdio.h>
#include <dlfcn.h>
int (*SBSSpringBoardServerPort)() = (int (*)())dlsym(RTLD_DEFAULT, "SBSSpringBoardServerPort");
int port = SBSSpringBoardServerPort();
void (*SBDimScreen)(int _port,BOOL shouldDim) = (void (*)(int _port,BOOL shouldDim))dlsym(RTLD_DEFAULT, "SBDimScreen");
and then use
SBDimScreen(port,YES);
whenever you want to dim, and
SBDimScreen(port,NO);
whenever you want to undim.
On iOS6:
void (*BKSDisplayServicesSetScreenBlanked)(BOOL blanked) = (void (*)(BOOL blanked))dlsym(RTLD_DEFAULT, "BKSDisplayServicesSetScreenBlanked");
and then use:
BKSDisplayServicesSetScreenBlanked(1); // 1 to dim, 0 to undim
"Dim" here means totally turn off the screen. This is what the system uses when e.g. a proximity event occurs while in a call.
The only way I know of, public or private, is using the power button.
You might look at -[UIApplication setProximitySensingEnabled:(BOOL)], or -[UIApplication setIdleTimerDisabled:YES], this might lead to something useful
Have you tried:
[[UIScreen mainScreen] setBrightness: yourvalue];
SO question 8936999: iPhone: How can we programmatically change the brightness of the screen?
Proximity doesn't work on all devices. There's a much simpler solution to this problem without resorting to private APIs.
Swift
UIScreen.main.wantsSoftwareDimming = true
UIScreen.main.brightness = 0.0
Without wantsSoftwareDimming, the backlight will never completely turn off.
The docs have this cautionary sentence:
The default value is false. Enabling it may cause a loss in performance.
I do not think there is any to turn off the display (simulating iphone sleep button) except changing the brightness.
This link might help.

Can I record a video without using UIImagePickerController?

Can I record a video without using UIImagePickerController?
Of course without needing to jailbreak or anything else that would cause the App Store to reject the app.
I think there is a way to access video device not using UIImagePickerController because these camera applications can record video and work on iPhone 2G/3G which utilizes ffmpeg:
iVideoCamera
iVidCam
I pick this code up by googling.
AVFormatParameters formatParams;
AVInputFormat *iformat;
formatParams.device = "/dev/video0";
formatParams.channel = 0;
formatParams.standard = "ntsc";
formatParams.width = 640;
formatParams.height = 480;
formatParams.frame_rate = 29;
formatParams.frame_rate_base = 1;
filename = "";
iformat = av_find_input_format("video4linux");
av_open_input_file(&ffmpegFormatContext,
filename, iformat, 0, &formatParams);
This code tell me how to open camera device, but I don't know device path of iPhone.
How do iVideoCamera and iVidCam record video?
Both of these use CoreSurface which is a private API. You can google it for more information. In iOS 4, there are new API's to get direct frame access from the camera.

iPhone video player - Change player orientation (w/ Playlist)

I need to rotate the video player on iPhone (or let it autorotate).
I know the webview solution, but here come the problem, I need to play several video (distant), and WebView can't provide me a stopSelector.
I know the fact that setOrientation is a private API.
Is there a solution ?
Try with this:
[moviePlayer setOrientation:UIDeviceOrientationLandscapeRight animated:NO];
As you surely know, this solution will be rejected by Apple, as setOrientation for movie player is undocumented and part of the Private API.
I believe there's none.
I know there's people that pre-rotated a movie in order to make it appear
as if it were in portrait mode, but it's a bit ugly.
update: it's supported on 3.2/4.0 using MPMoviePlayerController .
I'm answering my own question :
Since iOS 3.2 MPMoviePlayerViewController can just return YES to shouldAutorotate method.

Programmatically powering off an iPhone?

Is it possible to programmatically power off an iPhone or does Apple disallow this?
If Apple disallows this, is it possible to programmatically mute the sound on an iPhone?
The iPhone applications you create with the official SDK are sandboxes in and of themselves. Walled off sandboxes with barbed wire.
You won't be able to turn off the power. And muting sounds other than your own applications' sounds amounts to being able to turn off the iPod playback.
I don't have any evidence for that, but this would involve modifying the "UserExperience" - which is something that Apple never would allow (and why still many people jailbreak their phones).
And this involves "power off" as well as "mute sound" - because both could destroy the UX (you wait for an important call, but application X broke the sound).
Is it possible to programmatically power off apple iPhone or does apple dissalow this. If apple disallow this is it possible to programmatically mute the sound on iPhone?
Apple prevents you from affecting the functionality of other apps and the core phone functions. When in doubt, if you want to do something phone-wide, you can't.
Plus, to mute the phone, you'd also have to figure out some way of making the physical mute switch on the side of the phone match the phone's mute setting. That's not going to happen with software!
I'm not sure how powering down the device and muting the device are reasonable alternatives in your app, but the bottom line is that you can't power down the device. However, you can mute the sound of your own app or the iPod app using the MPMusicPlayerController class.
The code looks like this for your app:
MPMusicPlayerController *player = [MPMusicPlayerController applicationMusicPlayer];
player.volume = 0.0f;
And, this for the iPod:
MPMusicPlayerController *player = [MPMusicPlayerController iPodMusicPlayer];
player.volume = 0.0f;
Anything you do that affects anything external to your application wont make it through the approval process (besides push notifications). You can certainly mute the sound in your app by simply pausing, stopping, or setting the volume to zero for all sounds you are playing. If you mean make the phone be mute globally, no.
You can't turn the device off through software. You can set the music playback volume with the MPMusicPlayerController class, the docs suggest you can't change the volume of the
iPod player though.