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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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
})
回答3:
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).