I'm creating custom overlay view for video recording.
I've add a button to start/stop recording:
[takePhotoBut addTarget:imagePickerController action:#selector(toogleRecord:) forControlEvents:UIControlEventTouchUpInside];
which calls [super startVideoCapture]; or [super stopVideoCapture]; in my custom UIImagePickerController. Also I've set delegate
CustomPickerController *imagePickerController= [[CustomPickerController alloc]init];
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
and I expect to get notified about imagePickerController:didFinishPickingMediaWithInfo:, but I get no response. I believe it happens, because ios wait till user clicks "Use video". But I want to get notified without user clicking that button. Are there any workarounds??
EDIT 1
the way I'm presenting ImagePicker:
[self presentViewController:imagePickerController animated:YES completion:nil];
It is not property on my VC.
Check whether your imagePickerController cameraCaptureMode set to UIImagePickerControllerCameraCaptureModeVideo
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
This solves my issue.
I had the same issue. Fixed it by hiding the camera controls.
imagePickerController.showsCameraControls = NO;
Related
Using the following code:
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (!self.alreadyAppeared) {
[self performSelector:#selector(showCamera) withObject:nil afterDelay:0.3];
}
}
-(void)showCamera
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.delegate = self;
[self presentViewController: picker animated:YES completion:NULL];
}
my app works perfectly. However if I change the
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
to
picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
I lose the image. The following code is how I capture the image and set an imageview within my app. I use a Nav controller to return to the app:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
self.cf.imageView.image = chosenImage;
NSLog(#"%#",chosenImage);
[picker dismissViewControllerAnimated:YES completion:NULL];
// pop back to previous controller
NSArray *myControllers = self.nc.viewControllers;
int previous = (int)myControllers.count - 2;
UIViewController *previousController = [myControllers objectAtIndex:previous];
[self.nc popToViewController:previousController animated:YES];
}
Again, this works just fine on my iPad and it works just fine using the front camera. Even when using the rear camera the chosen image (that I log) appears correct. Does anybody have any idea why the rear camera setting would have such an effect?
One other item: I get this very irritating message that has about 1,000 different explanations none of which get rid of the message:
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
When using the iPhone 6 and 6 plus, you must prevent your views from reloading each time you navigate away from the camera control (picker). My app uses a View Controller that creates a dynamic view which is a form. Each field on that form is pulled from a web service and becomes a subview of the form. That includes the camera field, which I use a viewcontroller and xib to build the field. The form view builds the entire form through a drawRect method. The camera field attempts to call that method each time it navigates away. I prevent it from reloading and that appears to have solved the issue.
A more standard app may create the camera field dynamically in viewDidAppear method of the main view controller. If you have the main view controller set as the delegate for the camera field, it will still call the viewDidAppear when it navigates away from the picker. That must be prevented or you will lose the image.
The really funny thing here is that this only happens on iPhone 6 and 6 plus. All other devices do not attempt to reload the views ... go figure.
As in the title, I do not manage to have that callback called in order to dismiss the game center view controller neither on my iOS 7 iPhone nor iOS 8 iPad. This is the code I use:
GKGameCenterViewController *controller=nil;
- (IBAction)achievementButtonClicked:(id)sender {
if (!controller){
controller=[[GKGameCenterViewController alloc] init];
controller.delegate=self;
}
NSLog(#"controller=%#", controller);
if (controller) [self presentViewController:controller animated:YES completion:nil];
}
-(void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController{
[gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
// I also tried [self dismissViewControllerAnimated:YES completion:nil] but anyway the function seems to not even enter here
}
If I take the function off, the delegate complaints it is missing, so the issue should not be connected to that. What might that be and how to fix it?
My problem is that I used:
controller.delegate=self;
omitting:
controller.gameCenterDelegate = self;
Once inserted the latter, the view controller dismisses without problems, both when I manually present the controller and when it is shown to login her. I really wonder why that beast has too delegates, if not to confuse developers...
I am using a regular UIImagePickerController to capture photo using the device camera. Following is the code I am using to create the UIImagePickerController,
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.imagePickerController.allowsEditing = NO;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.imagePickerController.delegate = self;
and following is the code that I am using to display the UIImagePickerController
[self presentViewController:self.imagePickerController animated:YES completion:nil];
Now, when the UIImagePickerController is presented, if I zoom to capture and come back to my presenting view controller, the app crashes irregularly with BAD_ACCESS. After editing the scheme and some debugging, I see the following error,
-[PLImagePickerCameraView didHideZoomSlider:]: message sent to deallocated instance 0x140109400
It seems that the zoom slider delegate is called on an unallocated instance. Anyone else observed this behaviour? I am using working on iOS 8.1 and testing it on iPhone 5S. The search for PLImagePickerCameraView doesn't yield much. Any insights would be really helpful before I decide to go with custom Picker.
I experienced the UIImagePickerController zoom crash, as well. Adding a delay fixed most, but not all, of the crashes.
The root cause is the controller attempting to callback to a delegate after the delegate has been deallocated. I ended up implementing a subclassed UIImagePickerController to remove the delegate of the slider view.
You can find some sample code I posted on a similar question.
To load the Game Center leaderboard, I currently call:
-(void) showLeaderboard:(NSString*)leaderboardId
{
GKLeaderboardViewController *viewController = [GKLeaderboardViewController new];
viewController.leaderboardDelegate = self;
if (leaderboardId)
{
viewController.category = leaderboardId;
}
[[self topViewController] presentViewController:viewController animated:YES completion:nil];
}
However this always loads up the default leaderboard, and then the user much press the back button to view all the available leaderboards.
Since my method is called from the main menu of my game, this isn't really appropriate to take my player to level 1's leaderboard.
How can I load up the view controller to already just be displaying all the available leaderboards, rather than make my player hit the back button...
Desired Result...
What happens...
Instead of GKLeaderboardViewController, you are looking for GKGameCenterViewController.
GKGameCenterViewController *viewController = [GKGameCenterViewController new];
viewController.viewState = GKGameCenterViewControllerStateLeaderboards;
You may want to load either GKGameCenterViewController or GKLeaderboardViewController depending on weather leaderboardId is set or not.
If that doesn't work, you should try this workaround.
On a communityapp development, I have the task of making an iPhone app into an iPad app.
Following the documentation, I used the following code to spawn my camera view :
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.delegate = self;
self.imagePickerController.sourceType = sourceType;
if (sourceType == UIImagePickerControllerSourceTypeCamera) {
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
self.imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
self.imagePickerController.allowsEditing = YES;
self.imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
}
popover = [[UIPopoverController alloc] initWithContentViewController:self.imagePickerController];
[popover presentPopoverFromRect:self.profilePicture.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
return;
}
But when spawned, I get this annoying "extra ghostly" camera button...
It doesn't work, and seems only to taunt me.
If I ask the object to hide its input buttons, ALL buttons disappear. I see no way of being able to tell that specific button to sod off.
UPDATE
I discovered it's only there the first time. If I close and reopen the popover, it's gone...
Sadly, this appears to be a bug in iOS 6 itself. There are a few possible workarounds, however.
You can set the showsCameraControls property of the image picker to false. This will remove the ghostly image, but, the other controls will be removed as well. You'll have to write your own view with buttons and whatnot to call the correct actions.
You say if you close and reopen the popover, the button goes away. It may be possible for you to set the showsCameraControls property of the picker to false, and then back to true before the picker is displayed. If it doesn't work, try creating a sort-of fake open/close action when the picker is initialized.