Store taken photos and videos from app to iOS Camera Roll
Posted By : Avilash Choudhary | 29-Jun-2015
If you are implementing photos and videos functionality in your cordova project using Camera and Media-capture plugin and you want to store taken photos and videos in iOS Camera Roll.
For photos, Use this method navigator.camera.getPicture this method and set saveToPhotoAlbum:true in options
navigator.camera.getPicture(function(imageUrl) { //console.log('capture photo url ‘+ imageUrl); }, attachMedia.onFail, { quality : 50, destinationType : navigator.camera.DestinationType.FILE_URI, correctOrientation : true, targetWidth : 640, saveToPhotoAlbum : true }); // you can also set destinationType: navigator.camera.DestinationType.DATA_URL this will return the base64 of that image.
Whenever User take the picture from camera in your app then that picture will also be available in device camera roll.
For Videos, Use navigator.device.capture.captureVideo and set saveToPhotoAlbum:true in options
navigator.device.capture.captureVideo(function(videoData){ //console.log("video shoot “+videoData); },attachMedia.captureVideoError, { limit : 1, duration: 60, saveToPhotoAlbum:true });
When you set the saveToPhotoAlbum:true this will save the video in iOS camera roll but To achieve this you also need to modify some code in CDVCapture.m file, you can find this file in plugins section in your Xcode. In CDVCapture.m find the processVideo method near 277 line number. Check the image.
There is some code commented you need to uncomment that code.you need to uncomment the code below this line /* don't need, it should automatically get saved */ .
When you uncomment this code, the videos taken from your app will be saved also in iOS Camera Roll.
Most of the apps which provide video downloading functionality set saveToPhotoAlbum:false to restrict free user to save video on camera roll. They unlock this feature when user buy that feature they just set it true now user will be able to save videos on their camera roll.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Avilash Choudhary
Avilash has excellent experience in developing mobile and web applications using jQuery , Javascript and PhoneGap. His hobbies are watching and playing cricket.