ios8 avfoundation camera freeze upon start - camera

My camera freezes when the app starts. The only way to unfreeze it is to go back to the home screen (without closing the app) and reopening it.
I have used [session startRunning]in my ViewWillAppear and ViewDidAppear, but nothing works. Before my phone ran iOS 8, everything worked fine.

you should add the [session startRunning] in the main thread just like this:
dispatch_async(dispatch_get_main_queue(), ^{
if (![session isRunning]) {
[session startRunning];
}
});

Related

How to stop AVAudioPlayer once we navigate from one view to into other view in iOS8?

I am fresher to iOS. I am using AVFoundation framework for AVAudioPlayer. This is used for running background sound when user enters into application home screen. This background sound should be stopped when it goes to other views and should be enabled when user come back to the home screen again. Below code is working fine in IOS7, when I upgrade to IOS8 background sound continuously playing and doesn’t stop when I go to other views. Kindly help me in this issue.
I am using below code for start and stop the player
NSString *pewPewPath = [[NSBundle mainBundle]pathForResource:#"background" ofType:#"mp3"];
NSURL *pewPewURL = [NSURL fileURLWithPath:pewPewPath];
NSData *data1 = [NSData dataWithContentsOfURL:pewPewURL];
audio = [[AVAudioPlayer alloc] initWithData:data1 error:nil];
audio.volume=8;
[audio play];
Call the [audio stop]; and set nil to the audio instance when you are navigating to another view. And write this code before you call the next view controller.

iOS7 sending SMS from inside the app has a misaligned modal view

I'm writing an app where I need to allow the user sending SMS from within the app.
It works fine on iOS6 but not on iOS7.
When I'm trying to send a text message, the modal view appears but there is a strange gap between the "to" field and the list of possible contacts.
After selecting the first contact, the "to" field slides up and disappears and then I see past messages and my new message but with the same gap again.
I'm attaching two images showing the issue:
Here is the code I'm using:
if([MFMessageComposeViewController canSendText]) {
NSArray *recipents = nil;
NSString *message = #"Let's go";
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[messageController setBody:message];
[self presentModalViewController:messageController animated:YES];
}
Please tell me if know you know how to fix this issue.
Thanks!
Additional info:
This bug only happens in iOS 7.x not in in iOS 6.x
Also, if I use the MFMailComposeViewControllerDelegate to send emails, it works just fine (although they are both implemented by MessageUI.h)...
Ok, I figured it out.
The issue happens because I have a custom UINavigationController.
In my AppDelegate, I had the following code:
UIImage *navBarImage = [UIImage imageNamed:#"BarIos7.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
Once I removed it, everything started working fine.

UIAlertView lags, leaves dim effect, then causes the screen to flicker on iOS 6.1.3

I have one question related to screen flickering in iOS 6.1.3. When I dismiss the UIAlertView (When I press OK button of UIAlertView in my App) the App gives Dim effect and then flickering starts. It always works same as soon as UIAlertView Ok button pressed.
But when I leave the app stable for some time the flickering automatically stops or when I change the orientation mode i.e. from landscape to Portrait then again to Landscape the flickering stops.
I got the solution for same problem in iOS6.1.2. But that solution does not work for iOS6.1.3.
This is happening because you're displaying that UIAlertView from a background thread - that's never officially been supported, but it didn't start actually causing problems until iOS 6.1.3. Anyway, just launch the UIAlertView from the main thread (performSelectorOnMainThread:) and it should work fine.
This will resolve the problem, just Launch the UIAlertView from the main thread using dispatch_async.
eg.
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:NSLocalizedString(#"Internet Status",nil) message:NSLocalizedString(#"here is your message",nil) delegate:self cancelButtonTitle:NSLocalizedString(#"OK",nil) otherButtonTitles:nil,nil];
[alt show];
});

How to handle mountain lion notifications clicks

I just wanted to add some notifications to Gyazo app.
I finally able to send notifications to the notifications center http://korniltsev.ru/p/jz6m3Nm.png
however when i click on it and the app is not launched it launches in some strange way:
it shows empty window(even if i set it visibleAtLaunch to 0) and nothing happens;http://korniltsev.ru/p/jz6mvk0.png
the code i'm trying to use is here:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSUserNotification * clicked = [[aNotification userInfo]
objectForKey:NSApplicationLaunchUserNotificationKey];
if (clicked){
[NSApp terminate:self];
return;
}
...
I send notifications like this
NSUserNotificationCenter *manager = [NSUserNotificationCenter defaultUserNotificationCenter];
NSUserNotification *urlNotification = [[NSUserNotification alloc]init];
[urlNotification setTitle:appName];
[urlNotification setInformativeText:url];
[manager deliverNotification:urlNotification];
What am i doing wrong?
[NSApp terminate:self] has a lot of side effects. Are you sure these side effects are not creating your blank window? Have you tried calling [NSApp terminate:self] immediately in applicationDidFinishLaunching and making sure you application quits cleanly in every case? If it does not you will likely have to look at what you are doing in your application's document controller (if you have one) and applicationShouldTerminate.

MPMoviePlayerController iOS play audio file issue

Hi all I am using MPMoviePlayerController to play both video (mp4) and audio (mp3) files. I am facing an issue when the view is removed form screen, the audio keeps playing in the background, video is ok. On iOS 4.3 everything works great, but when I switch to iOS5 and attempt to play audio and press back (remove the view) the audio is still pressent in the background. Is there something different in how MPMoviePlayerController handles audio files in 4.3 and 5 ? I am using the same code for playing both video/audio.
moviePlayBackDidFinish method, where I stop the player
[player setInitialPlaybackTime:-1];
[player stop];
player = nil;
[[player view] removeFromSuperview];
[player release];
Any help is appreciated :)
use this code to pause the audio/video in the MPMoviePlayerController
-(void)viewWillDisappear:(BOOL)animated
{
[mediaPlayer pause];
}