_UIImagePickerControllerUserDidCaptureItem not called xcode 6

十年热恋 提交于 2019-12-13 01:26:18

问题


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).



来源:https://stackoverflow.com/questions/26392220/uiimagepickercontrolleruserdidcaptureitem-not-called-xcode-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!