device Orientation to statusBar Orientation changes - iphone

I have created a device orientation listener to catch when the device is rotated, like so
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(jumpBarButtonPosition)
name:#"UIDeviceOrientationDidChangeNotification" object:nil];
however inside the jumpBarButtonPosition method I have changed from using UIDeviceOrientation to statusBarOrientation, so I am woundering what I could replace UIDeviceOrientationDidChangeNotification with in order to only receive notifications about the statudBarOrientation changes.

Don't type it as a string:#"UIDeviceOrientationDidChangeNotification" use:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(jumpBarButtonPosition)
name:UIDeviceOrientationDidChangeNotification object:nil];

Related

UIWebView and MPMoviePlayerController

I hvae addd one webview having youtube link. When user play viedo it defaults open iOS movie player. I want to track notification of that movie player when it exits full screen or playing stopped. I have tried all notification generated by MPMoviewPlayerController . None of them are being fired. It fiers only when we instatinate MPMoviewPlayerViewCotntroller object and present MPMoviewPlayer from that.
That's becuase Youtube videos inside UIWebView are not MPMoviewPlayerViewCotntroller.
On iOS7:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerWillEnterFullscreen:)
name:#"UIMoviePlayerControllerDidEnterFullscreenNotification"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playerWillExitFullscreen:)
name:#"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
On iOS8 it's a bit of a problem because these events are gone, and you need to add observer like so:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ios8EnterFullscreen:)
name:UIWindowDidBecomeVisibleNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ios8ExitFullscreen:)
name:UIWindowDidBecomeHiddenNotification object:nil];
And check that when it fires it is indeed a movie player (because it fires also on UIAlertView and stuff):
- (void)ios8EnterFullscreen:(NSNotification *)notification
{
if ([notification.object isMemberOfClass:[UIWindow class]])
{
//do your thing...
}
}

How to remove observer

I have an ARC enabled project
There are few observers added in viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(getSipNotification:) name:#"getSipNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(syncExtensionData:) name:#"syncExtensionData" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(showLocalNotification:) name:#"showLocalNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(outgoingCall:) name:#"outgoingCall" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playRingtone) name:#"playRingtone" object:nil];
I want to remove all observers so I added following line in viewDidUnload
[[NSNotificationCenter defaultCenter] removeObserver:self];
Now my question is, is this remove all observers?
If not how can do it?
UPDATE
If I want to remove a single observer how can do it?
Can you help me please.
Yes, It will remove all observers.
[[NSNotificationCenter defaultCenter] removeObserver:self];
And you can remove a particular observer like this...
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"syncExtensionData" object:nil];
In my application i used this notification :
for particular observer remove this way :
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(deviceRotatedFeedBackView:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void)deviceRotatedFeedBackView:(NSNotification*)notification
{
//right whetever you want
}
- (void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
may be it will helpful to you.
Yes it'll remove all the observers in your class.
You can use following to remove single observer:
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"getSipNotification" object:nil];
To remove individual observer.
viewDidUnload is deprecated in iOS6 and later, so Your observer never be removed from notification center in iOS6 and later. To remove single observer try
- (void)removeObserver:(id)notificationObserver name:(NSString *)notificationName object:(id)notificationSender

how to create Proximity Sensor observer?

i want to create and observer that checks for a change in proximity sensor. i am using this code.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(proximityChanged:) name:#"UIDeviceProximityStateDidChangeNotification" object:device];
but it give an error of "Use of undeclared identifier 'device'"
please help.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(proximityChanged:)
name:#"UIDeviceProximityStateDidChangeNotification"
object:nil];
Do like this way you set nil to objcet.

MPMovieNaturalSizeAvailableNotification is not working?

I added a notification with the following code,
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(videoLoadingComplete)
name:MPMovieNaturalSizeAvailableNotification
object:self.streamPlayer];
but it did not enter in the videoLoadingComplete function even after the video stars playing.
You can use following code
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviestart:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
-(void)moviestart
{
//your code here
}

postNotificationName not calling observer method

I am trying to call a method within an uiview from AppDelegate using the NSNotificationCenter to no avail..
AppDelegate.m
[[NSNotificationCenter defaultCenter] postNotificationName:#"ProcessDidComplete" object:items];
Then via MainStoryboard, the main view is loaded which controller class is MainViewController
in MainViewController.h viewDidLoad i have
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ProcessDidComplete:) name:#"ProcessDidComplete" object:nil];
and then the method
- (void) ProcessDidComplete:(NSNotification *)pNotification
but it never gets called.
Thanks for any help!
just change a way..
First add observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ProcessDidComplete:) name:#"ProcessDidComplete" object:nil];
Then Post Notification
[[NSNotificationCenter defaultCenter] postNotificationName:#"ProcessDidComplete" object:items];
Finally remove in viewWillDisappear
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"ProcessDidComplete" object:nil];
Your code looks okay, which makes me wonder where in your app delegate you post the notification?
If you post the notification before you add the observer in the view controlller, then the notification will never be received. Can you not send the message to the main view controller directly, i.e., as a property, rather than using notifications?
Just wanted to note here that iOS notification names are case-sensitive:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handUpdate:) name:#"scheduleUpdated" object:nil];
will not respond to:
[[NSNotificationCenter defaultCenter] postNotificationName:#"ScheduleUpdated" object:items];
(as I spent the last 20 minutes figuring out...)