1

我们使用 phonegap 制作了一个 Win8 应用程序。该应用程序还引用了用于执行某些异步任务的 Windows 运行时组件。该应用程序具有相机功能,其中调用相机,拍摄照片,然后在成功回调函数中将照片显示在屏幕上。直接从 Visual Studio Express 运行时,一切正常。当我们创建应用程序包并使用 Metro Sideloader 或 Powershell 部署它时,就会出现问题。永远不会调用相机成功回调函数。调用相机的代码是这样的:

    CameraService = function() {
        var that = {};

        that.invokecamera = function(callback) {
            try {
                GLOBALS.callback = callback;
                if (GLOBALS.Ready) {
                    navigator.camera.getPicture(that.onSuccess, GLOBALS.ThrowException, {
                        quality : 50,
                        saveToPhotoAlbum : true,
                        destinationType : Camera.DestinationType.FILE_URI
                    });
                }
            } catch (err) {
                alert(err);
            } finally {
            }
        }
        that.onSuccess=function(imageURI) {
        GLOBALS.ImagePath = imageURI;
        GLOBALS.callback(imageURI);
    }
        return that;
    }
4

1 回答 1

0

好的,所以我想出了这里提到的问题:

已安装应用程序的问题

要解决此问题,如链接中所述,已替换

Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {

var storageFolder = Windows.Storage.ApplicationData.current.localFolder;

在 cordova.js 文件中。我正在使用科尔多瓦 2.4.0。

一个更详细的例子

Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
                                        storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (file) {
                                            file.openAsync(Windows.Storage.FileAccessMode.readWrite).done(function (fileStream) {
                                                Windows.Storage.Streams.RandomAccessStream.copyAndCloseAsync(_stream, fileStream).done(function () {
                                                    var _imageUrl = URL.createObjectURL(file);
                                                    successCallback(_imageUrl);
                                                }, function () { errorCallback("Resize picture error."); });
                                            }, function () { errorCallback("Resize picture error."); });
                                        }, function () { errorCallback("Resize picture error."); });
                                    });

变成

var storageFolder = Windows.Storage.ApplicationData.current.localFolder;                                    
storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (file) {
                                            file.openAsync(Windows.Storage.FileAccessMode.readWrite).done(function (fileStream) {
                                                Windows.Storage.Streams.RandomAccessStream.copyAndCloseAsync(_stream, fileStream).done(function () {
                                                    var _imageUrl = URL.createObjectURL(file);
                                                    successCallback(_imageUrl);
                                                }, function () { errorCallback("Resize picture error."); });
                                            }, function () { errorCallback("Resize picture error."); });
                                        }, function () { errorCallback("Resize picture error."); });
于 2013-11-27T10:03:44.967 回答