Created
May 9, 2014 14:38
-
-
Save cfjedimaster/af298ed2bd0e3ce3ce54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Licensed to the Apache Software Foundation (ASF) under one | |
* or more contributor license agreements. See the NOTICE file | |
* distributed with this work for additional information | |
* regarding copyright ownership. The ASF licenses this file | |
* to you under the Apache License, Version 2.0 (the | |
* "License"); you may not use this file except in compliance | |
* with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, | |
* software distributed under the License is distributed on an | |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
* KIND, either express or implied. See the License for the | |
* specific language governing permissions and limitations | |
* under the License. | |
*/ | |
var app = { | |
// Application Constructor | |
initialize: function() { | |
this.bindEvents(); | |
}, | |
// Bind Event Listeners | |
// | |
// Bind any events that are required on startup. Common events are: | |
// 'load', 'deviceready', 'offline', and 'online'. | |
bindEvents: function() { | |
document.addEventListener('deviceready', this.onDeviceReady, false); | |
}, | |
// deviceready Event Handler | |
// | |
// The scope of 'this' is the event. In order to call the 'receivedEvent' | |
// function, we must explicity call 'app.receivedEvent(...);' | |
onDeviceReady: function() { | |
app.receivedEvent('deviceready'); | |
navigator.camera.getPicture(onSuccess, onFail, { quality: 50, | |
sourceType:Camera.PictureSourceType.PHOTOLIBRARY, | |
destinationType: Camera.DestinationType.FILE_URI | |
}); | |
function onFail(e) { | |
console.log("onFail"); | |
console.dir(e); | |
} | |
function onSuccess(uri) { | |
console.log("onSuccess"); | |
console.dir(uri); | |
document.querySelector("#img").src = uri; | |
console.log("ok i set the uri"); | |
} | |
}, | |
// Update DOM on a Received Event | |
receivedEvent: function(id) { | |
console.log('Received Event: ' + id); | |
} | |
}; |
(I am running cordova 3.5.0-0.2.6)
I upgraded to 3.6.0-0.2.9, bug still exists when testing this code in the PhoneGap app.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think this works in iOS 7. I tried this with a hello world and added an element in my index.html called 'img'. eg. It loads the file picker but after you select the image it does not display. I attempted your example here after 6 hours of trying to make this very thing work in my app, I think there is a bug in iOS with loading images from the /tmp/ directory. I tried moving the image to the root but still can't display it to the user. I can upload it to a server a load it back in though, that seems to work.