Skip to content

Instantly share code, notes, and snippets.

@exclusiveTanim
Created June 3, 2019 20:01
Show Gist options
  • Select an option

  • Save exclusiveTanim/66f0198080f96b51fcfc356e416f6941 to your computer and use it in GitHub Desktop.

Select an option

Save exclusiveTanim/66f0198080f96b51fcfc356e416f6941 to your computer and use it in GitHub Desktop.
base64encode image
var win = Ti.UI.createWindow();
win.open();
function takePhoto() {
Ti.Media.showCamera({
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
success: function(event) {
console.log(event);
if(event.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {
var image = event.media;
Ti.API.info(Ti.Utils.base64encode(image));
Ti.API.info(Ti.Utils.base64encode(image).text);
}
},
error: function(e) {
},
cancel: function(e) {
}
});
}
win.addEventListener('click', function(e) {
var hasCameraPermissions = Ti.Media.hasCameraPermissions();
if (hasCameraPermissions) {
takePhoto();
}
Ti.Media.requestCameraPermissions(function(e) {
takePhoto();
});
});
<ios>
<plist>
<dict>
<key>NSCameraUsageDescription</key>
<string>ADD_YOUR_PERMISSION_TEXT_HERE</string>
</dict>
</plist>
</ios>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment