MPMovieNaturalSizeAvailableNotification is not working? - iphone

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
}

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.

device Orientation to statusBar Orientation changes

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];

NSNotificationCenter not acting on the message

In one of my classes I post a notification:
[[NSNotificationCenter defaultCenter] postNotificationName:#"ALERTNOTI" object:self userInfo:nil];
In my app delegaate I listen:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMethod) name:#"ALERTNOTI" object:nil];
I use NSLog to track when I send and when the method myMethod gets called.
The method is not getting called despite me sending out the notification.
Is there something that I need to know about NSNotification? Is it tempermental?
do this changes
[[NSNotificationCenter defaultCenter] postNotificationName:#"ALERTNOTI" object:nil];
if you want to pass some object through the notification. then do this
ex: you want to pass an NSDictionary *dict
[[NSNotificationCenter defaultCenter] postNotificationName:#"ALERTNOTI" object:nil userInfo:dict];
the method you want to call via notification should be like this.
-(void)method:(NSNotification *) notif
{
// your code here.
//if you want to access your dict
NSDictionary *myDict=[notif userInfo];
}
Try this:
[[NSNotificationCenter defaultCenter] postNotificationName:#"ALERTNOTI" object:nil];