Howto hide UIPopoverController when UIWebView plays a fullscreen youtube movie? - ios

Please see the picture. After pressing the fullscreen button, the webview maximizes behind the UIPopover.
I tried to look out for MPMoviePlayerDidEnterFullscreenNotification, no luck.
I really don't want to ship my own UIPopoverController but this is my only "solution" at the moment. Using anything other than UIWebView is also not an option, as I am displaying YouTube-Movies.
Edit: I use a UIWebView, so there is no way to access the views/classes that are used internally.

According to this answer you can listen for UIMoviePlayerControllerDidEnterFullscreenNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeFinished:) name:#"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];

Related

Method in viewWillAppear and viewDidLoad didn't loaded

I have created a method to check the status of a server in my viewcontroller, I need to check this, everytime I will open the app.
I call [self checkStatus]; from viewWillAppear and viewDidLoad, but when I open the app, by clicking home button, and I try to open the app again (clicking the app icon in applications) this method is not called. I have a NSLog to view when it is launched or not.
I'm frustrated. Thanks for your help.
You can react to app changes using NotificationCenter:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(doSomething:) name:UIApplicationDidBecomeActiveNotification object:nil];
BTW: don't forget to removeObserver when you don't need it!
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
You can also use UIApplicationWillEnterForegroundNotification etc, depending what do you need.
You should read about app lifecycle on Apple Developer pages :). Read:
AppleDeveloperLink Especially section: "Execution States for Apps" to know more about app lifecycle.
StackOverflowLink to know more about view lifecycle.
iOS is not calling those methods again, but the delegate methods in the AppDelegate. You have to propagate the message to your controllers then.
I hope this will help you: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/

how can i detect when a user adds a keyboard language in settings

I want to receive a notification when the user adds a new keyboard language in the general settings and my application is in background.
Can anyone advise what code is needed to achieve this, or what preference key i should look for.
I have tried :-
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(defaultsChanged:)
name:NSUserDefaultsDidChangeNotification
object:nil];

Change Orientation for Youtube Videos ONLY

I currently have my iPhone application orientation set to Portrait only and was wondering if it were possible to change the orientation of a Youtube video, since it comes up in its own modal view controller?
I have a UIWebView that has a youtube video in there and when clicking it, it brings up the youtube/apple media player in a modal view controller. Is it possible to only change the orientation of this video player, to three orientations, and then reset it back to portrait once it is done?
I noticed in another post that these two help see if the movie player is active and inactive but I have not figured out how to change the orientation and then reset it. Any guidance and help is appreciated in advance. Thanks!
Code that is used to check for Movie Player start/finish
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeFinished:) name:#"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
Does anyone know how to control or grab the UIMoviePlayerController? Maybe there is someway to intercept it and control its orientation.

SDWebImage - avoid clearing image cache on entering background

I use SDWebImage in my app to load and cache images from the web. It works like a charm, but the only issue is that whenever I exit my app, even momentarily, the image cache gets cleared and all the images have to be downloaded again. This is especially a problem when the Internet connection is slow. I would like the images to be retained when I return to the app. Does anyone know how to achieve this?
Go to SDImageCache.m and seek method - (id)initWithNamespace:(NSString *)ns
There you will find such code:
// Subscribe to app events
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(clearMemory)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(cleanDisk)
name:UIApplicationWillTerminateNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(backgroundCleanDisk)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
Feel free to comment out or change anything if you want. I'd make an option to turn off these lines of code.
make sure you don't set the maxCacheSize of [SDImageCache sharedImageCache], if it is set when the app go to background, it will clear cache files to fit the maxCacheSize.
in cleanDisk method, you can see there is a check before removing files
if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize)
{
// ...
}
so if maxCacheSize is not set, it will do nothing.

How to judge whether it is a new day in an iOS project?

I have a UIView ,I want it to display in a new day.For example,today I launch my app,and that UIView comes to my view,but after this,I can't see that UIView until tomorrow.
So I want to know how to judge whether it is a new day to display the UIView?
You need to register for the UIApplicationSignificantTimeChangeNotification notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(timeChange) name:UIApplicationSignificantTimeChangeNotification object:nil];
Then in the timeChange method (or whatever you call it) update your view.
Don't forget to unregister:
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationSignificantTimeChangeNotification object:nil];
This notification is sent at midnight, if the user changes the time on their device, or the timezone changes. If your app is in the background when the change happens, it will get notified when the app returns to the foreground.

Resources