【问题标题】:Phonegap - ios9 File inputPhonegap - ios9 文件输入
【发布时间】:2015-12-18 07:34:40
【问题描述】:

我在使用 phonegap 和 iOS 9 时遇到了问题,这在 ios 8 上运行良好,当您单击文件输入时,它会在屏幕中间显示一个取消按钮,点击时不会执行任何操作。文件输入在 safari 中可以正常工作,但在我构建的应用程序中却不行。

我意识到有一个 phonegap 文件上传 API,但我将我的应用程序用作我网站移动版本的网络浏览器,所以我还没有构建一个完全原生的应用程序,这对我来说是一个快速的解决方案.

这可能是因为新的操作表样式或在 ios 9 中添加到操作表的新选项。

有没有人可以跳过操作表并在单击输入文件时直接进入相机胶卷的解决方案?或者有什么解决办法?

【问题讨论】:

  • 您是在使用phonegap 构建还是本地cordova 开发?如果您使用cordova,您使用的是哪个xcode 版本?

标签: javascript ios file cordova input


【解决方案1】:

我移至插件 - cordova-plugin-camera,这解决了问题。

点击输入类型文件后:

  e.preventDefault();

  navigator.notification.confirm(
    'Please select image', // message
    function (buttonIndex) {
      if (buttonIndex === 1) {
        photoFromSource(navigator.camera.PictureSourceType.CAMERA);
      } else {
        photoFromSource(navigator.camera.PictureSourceType.PHOTOLIBRARY);
      }
    },            // callback to invoke with index of button pressed
    'Image capture',           // title
    ['Camera', 'Gallery']     // buttonLabels
  );

  function photoFromSource(source) {
    var targetWidth = 640,
      targetHeight = 640,
      onSuccess = function (imageURI) {

        var image = new Image(),
          canvas = document.createElement('canvas'),
          canvasContext = canvas.getContext('2d');

        image.onload = function () {
          canvas.width = image.width;
          canvas.height = image.height;
          canvasContext.drawImage(image, 0, 0, image.width, image.height);

          var dataURL = canvas.toDataURL();

          self.model.set('imageData', dataURL);
          self.model.setDataAttr('image', true);
          self.render();
        };

        image.src = imageURI;
      },
      onFail = function (message) {
        // Ignore if no image seleted
        if (!/^no image selected$/.test(message))
          alert('Failed because: ' + message);
      },
      opts = {
         quality: 50,
         destinationType: navigator.camera.DestinationType.FILE_URI,
         sourceType: source,
         mediaType: navigator.camera.MediaType.PICTURE,
         targetWidth: targetWidth,
         targetHeight: targetHeight,
         encodingType: navigator.camera.EncodingType.JPEG,
         correctOrientation: true,
         cameraDirection: navigator.camera.Direction.BACK,
         saveToPhotoAlbum: false
      };

    try {
      navigator.camera.getPicture(onSuccess, onFail, opts);
    }
    catch (e) {
      alert('Could not capture image: ' + e);
    }
  };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多