Search code examples
objective-cuiimagepickercontrollerxcode6.1ios8.1opentok

UIImagePickerController opening Picture mode instead of Video Mode after using Opentok features


I am using Opentok v2.0 in my iOS App for the chat/call purposes with other online users. Application has a feature of recording videos too when internet is absent so they can be uploaded later on. Everything is working accordingly but when I record videos after using Opentok features, UIImagePickerController opens Picture mode instead of Video mode. Here is my code of invoking camera for the video recording.

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.picker.allowsEditing = NO;
    self.picker.delegate = self;
    self.picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
    self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
    [self presentViewController:self.picker animated:YES completion:nil];    
}

Is it Opentok bug or am I doing something wrong? Please share your thoughts

Regards


Solution

  • This is a bug as of OpenTok iOS SDK version 2.3.1. To work around the issue, you can use the code below after exiting your OpenTok Session and before opening the UIImagePickerController. I would suggest placing this in your sessionDidDisconnect method

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil];
    

    don't forget to set your Session object to nil for cleanup.

    Now, if you want to be able to enter back into a Session and have proper audio, you will need to call:

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
               withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
    

    You can place this line of code before connecting with the Session Object's connectWithToken method.