How to silence iPhone camera shutter sound? - iphone

I can snap a picture with the iPhone programmatically by calling [UIImagePickerController takePicture:], but when I do the iPhone plays a loud recording of a shutter click. When I google for how to turn off the click, I find advice to rename the sound file that the iPhone plays. It seems to me for my app to do that would lead to it being rejected from the App store for accessing system frameworks. Is there a programmatic way to shut off that sound? The nature of my app demands that the camera be silent.

I assume you have solved it since but your app supposed to fail on the Appstore validation as it doesn't comply with iOS Dev License agreement. See below:
Section 3.3.8: Any form of user or device data collection, or image,
picture or voice capture or recording (collectively "Recordings"), and
any form of data, content or information collection, processing,
maintenance, uploading, syncing, storage, transmission, sharing,
disclosure or use performed by, through or in connection with Your
Application must comply with all applicable privacy laws and
regulations as well as any related Program Requirements, including but
not limited to any notice or consent requirements. In particular, a
reasonably conspicuous audio, visual or other indicator must be
displayed to the user as part of the Application to indicate that a
Recording is taking place.

Not sure if you would want to do it...
The sound is there to let someone know a photo is being taken. The idea is to ensure privacy and safety of the public, especially children," something that Japan has already required of their snap-happy citizens
Japan and Korea already have laws that require this sound when taking pictures.
http://abcnews.go.com/Technology/story?id=6750825&page=1
excerpt:
"In Japan and Korea, Segan pointed out, in response to mounting reports of "underskirting," governments have passed laws similar to the one King proposes."

Renaming the sound file wouldn't be using a "private API"; it's simply not possible from within the sandbox (assuming you haven't broken out of the sandbox somehow).
However, on 4.0+, you can use AVCapture to take pictures instead. I'm not sure if AVCaptureStillImageOutput plays a shutter sound; a workaround is to use video frames.
I have to wonder what you mean by "the nature of my app" though. If you're trying to do some sort of live image processing, then video frames are a much better way to go in the first place. If you're trying to take pictures silently with the user's permission, then the user should be able to silence the shutter sound anyway. If you're trying to take pictures without the user's permission, you're probably violating some agreement with Apple.

For what it's worth, I was able to get this to work by using this code in the snapStillImage method of AVCapture framework using AVCaptureStillImageOutput. It works perfectly for me on iOS 8.3 iPhone 5. I have also confirmed that Apple won't reject your app if you use this:
MPVolumeView* volumeView = [[MPVolumeView alloc] init];
//find the volumeSlider
UISlider* volumeViewSlider = nil;
for (UIView *view in [volumeView subviews]){
if ([view.class.description isEqualToString:#"MPVolumeSlider"]){
volumeViewSlider = (UISlider*)view;
break;
}
}
[volumeViewSlider setValue:0.0f animated:YES];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
Swift 4:
var volumeView = MPVolumeView()
//find the volumeSlider
var volumeViewSlider: UISlider? = nil
for view: UIView in volumeView.subviews {
if (view.self.description == "MPVolumeSlider") {
volumeViewSlider = view as? UISlider
break
}
}
volumeViewSlider?.setValue(0.0, animated: true)
volumeViewSlider?.sendActions(for: .touchUpInside)

Related

Curious to know the trick for live wallpapers on lock screen on iPhone

This application and this application says it displays live wallpapers on lock screen. We have similar requirement.
From reviews came to know that it is playing music in background with silent volume, but it is not relevant to setting wallpapers.
Totally bummer topic for us. Can anyone please suggest some point where to begin.. ?
Referred this and Referred this questions on our forum, but says that it won't be approved by Apple. So how does current application exist on store ?
Note:
Please consider this as genuine programming questions as there is no starting point we can find.
If you play music, you can use MPNowPlayingInfoCenter (Available in iOS 5.0 and later.) to set things like cover art, title and artist on the lock screen. Your code could look like this:
NSMutableDictionary *currentTrackData = [[NSMutableDictionary alloc] init];
[currentTrackData setObject:"Some text" forKey:MPMediaItemPropertyTitle];
MPMediaItemArtwork *mediaItemArtwork =[[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:#"your image path"]];
[currentTrackData setObject:mediaItemArtwork forKey:MPMediaItemPropertyArtwork];
[mediaItemArtwork release];
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentTrackData;
Dont forget to import the media player framework:
#import <MediaPlayer/MediaPlayer.h>
The live lockscreen app must be doing it this way (MPNowPlayingInfoCenter) as you cant play music whilst using the app

view capturing in background

we can easily capture a view(screenshot) programmatically in iPhone.
But i am trying to capture screen automatically after every 5 seconds.that also, can be done.
But my main objective is , to capture screen, even if the app is closed, i.e in background.
Apple doesn't allow to background process to run for a long time, but can we do it for 5-10 min in background.
Capturing screen,even if the app is closed.Ofcourse user can close this function, within the app.
Apple might reject this, but is this possible ?
Regards
This is possible but it's not easy. You can register you app (via a .plist setting) as being a media app, this will allow it to run in the background. This is normally to allow media apps to continue playing music when the app is sent to the background. However if you are careful you can get it to do other thing in there too.
In your plist under "Required Background Modes" add a key "Item 0" and set it to "App plays Audio". This will mean you can do it.
You will then have to using AVAudioPlayer, play a silent sound that is say 5mins long, and then register one of your controllers for the AVPlayerItemDidPlayToEndTimeNotification notification. Then when this calls back, you can have your bit of code that, first takes a screenshot, and then starts the sound again.
This is the general concept, look somewhere like :
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_background-audio/
for how to set up the audio playing.
Just a note: APPLE WILL REJECT THIS!
If you are making an app for personal use only, this is fine, but will never make it to the app store.
Hoep this sheds some light on your situation! :)

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.

iPad SDK: Embedded YouTube movie plays fullscreen version behind UIWebView

I have a UIWebview within a UIScrollView. Within the webview I have an embedded YouTube movie. When I play the YouTube movie everything works fine, however, when I press the fullscreen button the movie starts playing behind the webview. Bringing the WebView to the front does not work, because I want the scrolling capabilities of the ScrollView to do horizontal scrolling.
Basically, you want to be able to detect when a movie starts playing fullscreen and arrange your views appropriately. Then, when the fullscreen playback ends you want to be able to get your views back to how they are.
The problem is there's no documented way to hook into or detect when a UIWebView triggers video playback in full screen.
I said 'documented way', because there are some notifications you can use to detect when a UIWebView triggers fullscreen playback. You can just listen out for them and rearrange your views accordingly. However, I don't necessarily recommend this, because they're undocumented and subject to change (in fact, they have a spelling mistake in them up until iOS 4.3, see answers below).
// For iOS 4.3 and above:
UIMoviePlayerControllerDidEnterFullscreenNotification
UIMoviePlayerControllerDidExitFullscreenNotification
// For iOS 4.2 and below:
UIMoviePlayerControllerDidEnterFullcreenNotification
UIMoviePlayerControllerDidExitFullcreenNotification // (note spelling mistake)
Finding these out was a bit of a pain - there are actually several more notifications that get triggered when a YouTube video in a UIWebView gets played back. To find them out you'll need to drop a breakpoint on all posting of notifications, and then manually inspect the memory locations of those notifications to figure out their string names. I don't actually think anyone has pulled these out before, because when I google them I get nothing. But they do work, promise!
I hope being able to get notified when the fullscreen playback is entered/exited will be helpful, with the massive caveat that Apple could change this undocumented behavior at any time. Your app won't get rejected outright for using them (because you're not calling any undocumented methods), and I've used it in shipping apps. But it's still not the best idea in the world...may be the only option you have though.
Edit: To clarify, based off the comment below: they're not constants, so you'd need to put them in quotes if you were registered for notifications.
For iOS 4.3+, Apple have changed the names of these notifications:
UIMoviePlayerControllerDidEnterFullcreenNotification now is UIMoviePlayerControllerDidEnterFullscreenNotification
UIMoviePlayerControllerDidExitFullcreenNotification now is UIMoviePlayerControllerDidExitFullscreenNotification
Please pay attention: The term "Fullcreen" has changed to "Fullscreen".
Thanks!
Just wanted to confirm that this works after playing around with it for awhile. You can get direct access to the view that the video is playing in. This is a blocks method of registering for the notification and pulling out the pertinent views.
Notice: You will need to delay adding subviews and/or access Apple internal subviews to remove the navbar for further customization.
[[NSNotificationCenter defaultCenter]
addObserverForName:#"UIMoviePlayerControllerDidEnterFullcreenNotification"
object:nil
queue:nil
usingBlock:^(NSNotification *note){
MPMoviePlayerController *theMovieController = [note object];
UIView *theDestinationVideoView = [[note userInfo]
objectForKey:#"UIMoviePlayerControllerFullscreenViewUserInfoKey"];
}];

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.