_UIImagePickerControllerUserDidCaptureItem not cal

2019-08-05 19:29发布

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

3条回答
男人必须洒脱
2楼-- · 2019-08-05 19:56

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

查看更多
一纸荒年 Trace。
3楼-- · 2019-08-05 19:59

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.

查看更多
我命由我不由天
4楼-- · 2019-08-05 20:07

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
})
查看更多
登录 后发表回答