Before iOS 8, the UIMoviePlayerControllerDidEnterFullscreenNotification notification was sent any time a media player went to fullscreen from a UIWebView. In iOS 8, this doesn't happen and some have suggested to listen for the AVPlayerItemBecameCurrentNotification notification instead. This doesn't appear to be sent from WKWebView. Listening for the UIWindowDidBecomeVisibleNotification notification doesn't work because it's fired for all windows that are added (including things like ad networks)
Bottom line, I've been working on this all night and I can't seem to figure out how to determine if a video was opened in full screen with a WKWebView. Any help would be appreciated.
Edit: To confirm, I created a blank project. Added a UIWebView and the AVPlayerItemBecameCurrentNotification listener to it and it got triggered when I played a video and it entered full screen. I switched that UIWebView to a WKWebView and that notification was no longer triggered.
This workaround seems to work on iOS8 & iPhone 6
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(windowBecameHidden:) name:UIWindowDidBecomeHiddenNotification object:nil];
return TRUE;
}
- (void)windowBecameHidden:(NSNotification *)notification {
UIWindow *window = notification.object;
if (window != self.window) { // Not my own window: assuming the video window was hidden, maybe add some more checks here.
// Add code here
}
}
I just need to do the same. I listened all notifications with this answer https://stackoverflow.com/a/7955014/1271424 and found: there are no notifications about fullscreen mode at all, except notifications about creating new window (_UIWindowContentWillRotateNotification) and about MPRemote (MPRemoteCommandTargetsDidChangeNotification).
Tested on iPad, 8.1.1
Related
I have an iOS app built in XCode with Objective C mainly for iPads.
Basically I want to detect inside my application of AirPlay Mirroring is active, so mainly if the device is mirroring to another screen.
I searched all around stackoverflow but I couldn't find what I needed for this.
Some answers said that I have to use UIScreenDidConnectNotification for this.
The thing is that I have to call a function if the mirroring is active or when mirroring is activated, also when mirroring is stopped. So I think I need a listener for the mirroring changes.
Can you please help me?
I am relatively new to iOS development so please don't get upset if I may not know all things.:)
Some answers I've found :
https://stackoverflow.com/a/30319663/2866662
https://stackoverflow.com/a/22321926/2866662
https://stackoverflow.com/a/9027616/2866662
https://stackoverflow.com/a/10576262/2866662
Thanks!
Here's how you can call any function by subscribing to the notification, you can do it in viewDidLoad or where you find necessary:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(receiveAirPlayNotification:)
name: UIScreenDidConnectNotification
object:nil];
And to receive it:
- (void) receiveAirPlayNotification:(NSNotification *) notification
{
//Do whatever you want here, or call another function
NSLog(#"Received Notification - %#", notification);
[self doMyThing];
}
My app receives all the notifications local and remote. And also working fine with showing Alerts.
But when i press Home button and remove app from app stack or from recent apps. And after that any notification come, my app informed me for notification in notification bar. And when i tapped the notification, this is just opening my app (not showing alert). [When app is in app Stack / recent apps and any notification arrives and after tapping on this will open the app and also show me alerts.]
Any one have solutions or faced problem like this.
Thank You
Try this code it will helps to you, you get notification info in didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif =[launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
if(localNotif) {
//get notification info
localNotif.userinfo
}
return YES;
}
I was wondering how would i pause my sprite kit scene when home button is pressed.
I found few answers here and tried it with notification center like this.
When my scene load:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(applicationDidEnterBackground)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
And then later the method that is called if enters to background:
- (void) applicationDidEnterBackground{
NSLog(#"Enter to background");
self.scene.view.paused =YES;
}
Problem here is that i get the NSLog message so applicationDidEnterBackground method is being called properly. But problem is that when I return to application my app is not on "pause" mode.
So my pause statement (self.scene.view.paused =YES;) is not being called?
If I put exact statement somewhere else in code or if I make a pause button with this statement pause works just fine.
What is the problem? Why this won't work with notification center?
Sprite kit for iOS 8 automatically resumes your game after exiting background mode. It happens after applicationDidBecomeActive is called. Also, Sprite kit for iOS 8 automatically pauses your game when it moves to the background.
Update: The following are the states of skView.paused when enter/exiting background mode for Xcode 5 and 6.
Xcode 6
Deployment targets 7.0, 7.1**, 8.0, and 8.1
applicationWillResignActive = NO
applicationDidEnterBackground = YES
applicationWillEnterForeground = YES
applicationDidBecomeActive = YES
** When I ran on a device running iOS 7.1, the states were all NO
Xcode 5
Deployment targets 7.0 and 7.1
applicationWillResignActive = NO
applicationDidEnterBackground = NO
applicationWillEnterForeground = NO
applicationDidBecomeActive = NO
By the time your application has entered the background, it's probably too late.
Instead, we should register for the UIApplicationWillResignActiveNotification notification and handle our just-before-exit code when we receive this notification.
I have a little bug. I'm developing an iOS App.
If i receive a call, my app stays open and the screen for my entering call appears on my app. I would like to close my app if i have a call.
How can i fix that?
Thanks,
J.
The green, in-call status bar is not a bug but a feature. You don't need to close the app when the call comes.
Instead, make sure your views are resized properly when the in-call status bar appears.
As Per Apple Human Interface guidelines
Never quit an iOS app programmatically because people tend to interpret this as a crash.
However, if external circumstances prevent your app from functioning as intended, you need
to tell your users about the situation and explain what they can do about it. Depending on
how severe the app malfunction is, you have two choices.
Display an attractive screen that describes the problem and suggests a correction. A
screen provides feedback that reassures users that there’s nothing wrong with your app. It
puts users in control, letting them decide whether they want to take corrective action and
continue using your app or press the Home button and open a different app
If only some of your app's features are unavailable, display either a screen or an alert
when people use the feature. Display the alert only when people try to access the feature
that isn’t functioning. `
But again you handle your app accordingly when call comes by using the following notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(incomingCall:) name:CTCallStateIncoming object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callEnded:) name:CTCallStateDisconnected object:nil];
Srinivasan N's answer has the incorrect observer, you'll want to add this observer which will account for all scenarios: phone calls, Personal Hotspot, GPS/navigation, etc.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(adjustViews:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
}
- (void)adjustViews:(NSNotification *)notification
{
NSValue *rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
CGRect newFrame;
[rectValue getValue:&newFrame];
NSLog(#"Changed frame to: Width: %f, Height: %f", newFrame.size.width, newFrame.size.height);
// Adjust your views here
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Is there an API that allows me to know when NotificationCenter will pop a notification on the top of the screen while my app is running (for example for an incoming Message or email)?
It causes a big performance glitch to my game so I'd like to pause it and unpause once the notification has disappeared. If there is no event to listen to I can only think of monitoring FPS and pausing for a few seconds if it drops below a threshold. Any other suggestions?
EDIT: My answer is only for popup notifications, not for the ones that scroll on to the top of the screen. Sorry :(
In your app delegate, the method
- (void)applicationWillResignActive:(UIApplication *)application
will be called.
And then
- (void)applicationDidBecomeActive:(UIApplication *)application
when it's time to start up again.