Is it just me or _UIImagePickerControllerUserDidCaptureItem notification from uiimagepickercontroller stopped working on iOS 8 and XCode 6. I use it to rotate the camera overlay after the user taked a picture.
PLease help
It's pretty strange, but in iOS 8 setting observer using
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(imagePickerControllerDidCapture) name:#"_UIImagePickerControllerUserDidCaptureItem" object:nil];
doesn't work for UIImagePickerController, but using block works fine:
self.imagePickerControllerDidCaptureObserver = [[NSNotificationCenter defaultCenter] addObserverForName:#"_UIImagePickerControllerUserDidCaptureItem" object:nil queue:nil usingBlock:^(NSNotification *note) {
[self removeCameraOverlay];
}];
Please notice that in this approach you should store observer object to detach it later using
[[NSNotificationCenter defaultCenter] removeObserver:imagePickerControllerDidCaptureObserver];
In situations like that it very useful to use
[[NSNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *note) {
NSLog(#"Notification: %#", note.name);
}];
to monitor all notifications, see names and moments it fires.
I also see the same issue with iOS 8 but using block works as mentioned by Amoneron in his answer.
Here's how to do it in Swift:
NSNotificationCenter.defaultCenter().addObserverForName("_UIImagePickerControllerUserDidCaptureItem", object:nil, queue:nil, usingBlock: { note in
// do something here
})
It still works for me, though I am using the notification center for that.
NSNotificationCenter.DefaultCenter.AddObserver (new NSString ("_UIImagePickerControllerUserDidCaptureItem"), HandleUserCapturedItem);
the code is in c# as I am using xamarin to develop, there should be something similar in objective-c since I'm basically using wrapper classes (built by xamarin).
Related
I used Xcode 6 with iOS 8 SDK.
If the video can't played, when starting MPMoviePlayer. MPMoviePlayerPlaybackDidFinishNotification not working.
I reference this article:
[How to get an error description when playback fails on MPMoviePlayerController
but iOS8 doesn't work.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(MPFinished: ) name:MPMoviePlayerPlaybackDidFinishNotification object:self.MoviePlayer];
How to do that can solve this problem? Thanks.
I had same issue and the only solution I found was to replace the MPMoviePlayerController by a AVPlayerViewController (available since iOS 8 in the AVKit framework).
Make sure the "object" parameter is of class MPMoviePlayerController and not MPMoviePlayerViewController.
If self.MoviePlayer is a MPMoviePlayerViewController, just change this:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(MPFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.MoviePlayer];
to this:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(MPFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.MoviePlayer.moviePlayer];
The object sending the notification is self.MoviePlayer.moviePlayer
I have tried to deal with this issue for too long. Please give me any of your thoughts.
I am presenting a View Controller from an SKScene by sending a Local Notification. [[NSNotificationCenter defaultCenter] postNotificationName:#"closeScene" object:nil];
The notification is handled in the beginning view controller.
- (void)viewDidLoad{ [[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(closeScene) name:#"closeScene" object:Nil];
[super viewDidLoad];}
Then:
-(void)closeScene {
//Remove the SKView, or present another viewController here.
constructionViewController *view = [[constructionViewController alloc] init];
[self presentViewController:view animated:YES completion:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"closeScene" object:nil];
}
And every time the notification is sent, I get the warning:
Warning: Attempt to present <constructinoViewController: 0x10ae64160> on <constructinoViewController: 0x10ab329d0> whose view is not in the window hierarchy!
Any help would more than appreciated. Thank you in advance!
When is closeScene called, exactly - before or after viewDidAppear gets called?
The error you're seeing usually happens when you try to present a view controller before the parent is actually displayed on screen. Typically this is because you've called presentViewController before the parent's viewDidAppear method has been called.
Try adding a logging statement to viewDidAppear and see whether it appears in the logs before or after your 'view is not in the window hierarchy' error. If it appears after you'll know what the problem is, and how to fix it (make sure presentViewController is only called after the parent view controller has been displayed). If it's before you probably have an altogether different problem...
I'm seeing that setting up a notification on QTMovieLoadStateDidChangeNotification has no effect and the target selector never gets called. Am I missing something?
In awakeFromNib:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieLoadStateDidChange:)
name:QTMovieLoadStateDidChangeNotification
object:nil];
On loading movie:
NSNumber *num = [NSNumber numberWithBool:YES];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
url, QTMovieURLAttribute,
nil];
self.mQTMovie1 = [[QTMovie alloc] initWithAttributes:attributes
error:&error];
Also
- (void)movieLoadStateDidChange:(NSNotification *)notification {
NSLog(#"movieLoadStateDidChange got called");
}
I'm not sure this is the answer but I've encountered this before. The cause in my case was a file whose codec was supported only by a third-party plugin (Flip4Mac in my case).
The load state notification isn't called until the movie finishes after it auto-plays (to nowhere). For long media files, it effectively looks like the notification is never called, since we rarely wait 5 minutes or an hour for a load notification when testing our code. To the user, it looks like the app simply isn't loading the file.
Having the user disable the plugin's auto-play-on-load in System Preferences resolves the issue but unfortunately this one support FAQ I can't get around since users of the app in question frequently use Flip4Mac to support files from common digital voice recorders.
I have a delegate method of an NSSplitView like this:
- (void)splitViewWillResizeSubviews:(NSNotification *)aNotification
{
NSLog(#"RESIZE!");
}
This method is called whenever I drag a divider, so it registered properly. I would like to call this from another object, and was thinking to use this:
[[NSNotificationCenter defaultCenter] postNotificationName:NSSplitViewWillResizeSubviewsNotification object:self];
According to the Apple docs, this is the notification that should be sent to call the delegate method. However, it does not work. Does anyone have an idea what I am doing wrong?
You can just invoke the method manually
NSSplitView * yourSplitView; //Get reference to your splitview
id yourSplitViewDelegate = [yourSplitView delegate];
[yourSplitViewDelegate splitViewWillResizeSubviews:nil];//Optionally create the NSNotification with relevant data
If you really want to go through notification center, make sure self in your question is the NSSplitView.
NSSplitView * yourSplitView; //Get reference to your splitview
[[NSNotificationCenter defaultCenter] postNotificationName:NSSplitViewWillResizeSubviewsNotification object:yourSplitView];
Turns out that I needed to manually register the delegate class for the NSSplitViewWillResizeSubviewsNotification notifications!
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(splitViewWillResizeSubviews:)
name:NSSplitViewWillResizeSubviewsNotification
object:vc];
where vc is the viewcontroller that should be sending the notifications.
This is unexpected behavior (to me), since an <NSSplitViewDelegate> is expected to register automatically for NSSplitView... notifications.
I have App, playing Videos from web
everything works fine
but when user leave the app for reading email or anything
and come back the player gone!! big problem
so, I want user resume watching after come back to app
here is my code so far
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didEnterforground) name:UIApplicationWillEnterForegroundNotification object:nil];
the Methods
- (void) didEnterBackground
{
[theMovie.moviePlayer pause];
NSLog(#"Playing pause");
}
- (void) didEnterforground
{
[theMovie.moviePlayer play];
NSLog(#"Playing resume");
}
for know I use [self presentMoviePlayerViewControllerAnimated:theMovie]; NOT playing in view
should that's code works but, nothing works
Please Help
Thanks in advance
The answer is very simple, edit info.plist.
Add background competence, required background modes, set category App plays audio
Try it!