I'm developing one app in which i want to capture an image at run time.
It has to work for both MAC PRO & Mac mini (If web cam is connected). When Camera takes picture small light will come at the time of taking snap, that should not come. Its not regarding the flash.
code snippet:
- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection
{
// If we already have an image we should use that instead
if ( currentImage ) return;
// Retain the videoFrame so it won't disappear
// don't forget to release!
CVBufferRetain(videoFrame);
// The Apple docs state that this action must be synchronized
// as this method will be run on another thread
#synchronized (self) {
currentImage = videoFrame;
}
// As stated above, this method will be called on another thread, so
// we perform the selector that handles the image on the main thread
[self performSelectorOnMainThread:#selector(saveImage) withObject:nil waitUntilDone:NO];
}
To capture picture i'm using the above method. Thanks in advance
According to this article, several older MacBooks' camera LEDs could be circumvented by tying into the circuit board logic directly.
To my knowledge, there is no longer this security loophole, nor is there an API available in Objective-C to disable the camera LED.
Related
Running on iOS 8, I need to change the UI when rotating my app.
Currently I am using this code:
-(BOOL)shouldAutorotate
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation != UIInterfaceOrientationUnknown) [self resetTabBar];
return YES;
}
What I do it remove the current UI and add a new UI appropriate to the orientation. However, my issue is that this method is called about 4 times every time a single rotation is made.
What is the correct way to make changes upon orientation change in iOS 8?
Timur Kuchkarov is correct, but I'll post the answer since I missed his comment the first time I checked this page.
The iOS 8 method of detecting orientation change (rotation) is implementing the following method of the view controller:
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
// Do view manipulation here.
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
Note: The controller's view has not yet transitioned to that size at this time, so be careful if your sizing code relies on the view's current dimensions.
The viewWillTransitionToSize:withTransitionCoordinator: method is called immediately before the view has transitioned to the new size, as Nick points out. However, the best way to run code immediately after the view has transitioned to the new size is to use a completion block in the method:
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
// your code here
}];
}
Thanks to the this answer for the code and to Nick for linking to it in his comment.
I am using ZBAR scanner for scanning bar codes. But it takes quite some time before the camera opens. In the meantime, i want to have a loading animation once the button is pressed and stop the animation after the camera is open. Can anyone plz tell how to detect as soon as the camera is open event handler in ios.
I'm not sure if this is what you are looking for, but I think you can use KVO (Key-value observing) to have event-handler mechanism.
There is this connected property that is KVO-compliant that might tell you when the camera opens (I am not sure though). Here's the documentation:
connected
Indicates whether the device is currently connected.
(read-only)
#property(nonatomic, readonly, getter=isConnected) BOOL connected
Discussion The value of this property indicates whether the device
represented by the receiver is connected and available for use as a
capture device. When the value of this property becomes NO for a given
instance, however, it will not become YES again. If the same physical
device again becomes available to the system, it will be represented
using a new instance of AVCaptureDevice.
You can observe the value of this property using Key-value observing
to be notified when a device is no longer available.
Then you can try to implement observer for this connected property by following the link below. Basically what you need to do is something like:
Event Handler
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if( [keyPath isEqualToString:#"connected"] ){
BOOL isConnected = [ [change objectForKey:NSKeyValueChangeNewKey] isEqualToNumber:[NSNumber numberWithInt:1] ];
if(isConnected){
//remove loading icon..
} else {
//show loading icon..
}
}
}
Event Registration
- (void)viewWillAppear:(BOOL)animated{
AVCaptureDevice *camDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
int flags = NSKeyValueObservingOptionNew;
[camDevice addObserver:self forKeyPath:#"connected" options:flags context:nil];
(...)
}
Here's the documentation that might help you:
KVO Programming Guide
NSKeyValueObserving Protocol
Hope this helps you! :)
I’m building an application which supports both video playback and recording (not simultaneously, it’s just two separate features it provides). In order to make the videos play after the app enters background and gets back, I had to add an App plays audio item to Required background modes in the plist (I’m using MPMoviePlayerController for playback).
This, however, causes a problem with my video recording (I’m using UIImagePickerController for it). Basically, even after the picker is dismissed (either by the Cancel button or when it’s finished picking media), the app still keeps the audio recording session running.
If I remove the App plays audio item from the plist, the ImagePickerController’s audio session stops misbehaving, but then I can’t resume the playback of MPMoviePlayerViewController on switching to app from background mode.
Is there a way I can customise the handling of the audio session so that both the MPMoviePlayerController and UIImagePickerController can work properly?
yes, there is a way you can customize the handling of the audio session for what you desire: don't try to set the App plays audio setting.
instead, in your AppDelegate code (which is usually in AppDelegate.m from the simple wizard projects provided), supply code in the applicationWillResignActive: method that will stop the playback in your MPMoviePlayerController, and then use applicationDidBecomeActive: to resume the playback at the point at which you paused it if so desired.
this will not only allow the video to be resumed after a temporary pause, but it will allow you to save the state so that the video can be resumed in case the app is removed from memory or in case the user causes it to be quit.
You can scratch the background modes and instead use notifications to pause/resume your player. See UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification in the UIApplication class reference.
You can snag some code and see this implemented in this class. Here is some of the relevant code from that class:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(_didBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(_willResignActive:)
name:UIApplicationWillResignActiveNotification
object:nil];
- (void) _didBecomeActive:(NSNotification*)notification {
if (_wasPlaying) {
[_movieController play];
}
}
- (void) _willResignActive:(NSNotification*)notification {
_wasPlaying = _movieController.currentPlaybackRate != 0.0;
if (_wasPlaying) {
[_movieController pause];
}
}
I'm using this example to make a simple audio player which involves using the QTKit framework, although I can't figure figure out how to make a 'toggle' play/pause button instead of two separate buttons.
I've tried using the following code and it doesn't work, the error message is: (Statement requires expression of scalar type ('void' invalid)
- (IBAction)togglePlayback:(id)sender;
{
if([self play])
{
[self stop];
}
else
{
[self play];
}
}
Any help would be appreciated, or if there is a better way to have an audio track play when the application opens with a toggle 'play/pause' switch.
Well it looks like [self play] doesn't return YES or NO. You could go for an instance variable (e.g. isPlaying) which you are toggling.
Btw - If you are targeting 10.7 lion or iOS you could go for AVFoundation/AVAudioPlayer which is a bit newer API.
I'm testing my iAd on my iPad, and I can't seem to get my ADInterstitialAd to load very often.
It does run occasionally but most of the time the first method below is called
- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError*)error{
NSLog(#"Ad Failed");
//[self cycleInterstitial];
}
However when I try to reload it upon failing.(see below method) It just fails over and over. I dont see why apple would let it just fail in a testing environment. I have read that the fill rate can be low, but it seems really low just for a test iPad app.
- (void)cycleInterstitial{
// Clean up the old interstitial...
interstitial.delegate = nil;
[interstitial release];
// and create a new interstitial. We set the delegate so that we can be notified of when
interstitial = [[ADInterstitialAd alloc] init];
interstitial.delegate = self;
}
Can anyone please advise? Thanks!
No, sorry. Apple is solely responsible for the fill rate of iAds, including interstitial iAds for iPad. As developers and users, we do not have any direct control over this.