October 2013
Intermediate to advanced
1053 pages
28h 7m
English
You want to allow your user to shoot a video using his iOS device, and you would like to be able to use that video from inside your application.
Use UIImagePickerController with the UIImagePickerControllerSourceTypeCamera source
type and the kUTTypeMovie media
type:
-(void)viewDidAppear:(BOOL)animated{[superviewDidAppear:animated];staticBOOLbeenHereBefore=NO;if(beenHereBefore){/* Only display the picker once as the viewDidAppear: method getscalled whenever the view of our view controller gets displayed */return;}else{beenHereBefore=YES;}if([selfisCameraAvailable]&&[selfdoesCameraSupportTakingPhotos]){UIImagePickerController*controller=[[UIImagePickerControlleralloc]init];controller.sourceType=UIImagePickerControllerSourceTypeCamera;controller.mediaTypes=@[(__bridgeNSString*)kUTTypeMovie];controller.allowsEditing=YES;controller.delegate=self;[selfpresentViewController:controlleranimated:YEScompletion:nil];}else{NSLog(@"Camera is not available.");}}
The isCameraAvailable and
doesCameraSupportShootingVideos
methods used in this sample code are implemented and discussed in
Recipe 15.1.
We will implement the delegate methods of the image picker controller like so:
-(void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary*)info{NSLog(@"Picker returned successfully.");NSLog(@"%@",info);NSString*mediaType=info[UIImagePickerControllerMediaType ...
Read now
Unlock full access