【问题标题】:RubyMotion AVCaptureDevice errorRubyMotion AVCaptureDevice 错误
【发布时间】:2014-03-21 13:49:37
【问题描述】:

我目前正在尝试使用 RubyMotion 并尝试使用 iPhone 的相机手电筒。我已经在我的 Rakefile 中“导入”了 AVFoundation 框架,但似乎还有其他问题。您知道以更简单的方式处理此问题的宝石吗?我查看了 ruby​​motion-wrappers.com,但没有一个很好。提前致谢。

这是我在应用崩溃时遇到的错误:

uninitialized constant Torch::AVMediaTypeVideo (NameError)

错误来自的行是这一行(来自以下类,第 3 行):

flashlight = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)

这是我的手电筒课

class Torch
  def torchOn
    flashlight = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    check = flashlight.lockForConfiguration(nil)
    if check
      flashlight.setTorchMode(AVCaptureModeOn)
      flashlight.unlockForConfiguration
    end
  end

  def torchOff
    flashlight = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    check = flashlight.lockForConfiguration(nil)
    if check
      flashlight.setTorchMode(AVCaptureModeOff)
      flashlight.unlockForConfiguration
    end
  end
end

这是我添加相应框架的Rakefile部分:

# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'
require 'rubygems'

begin
  require 'bundler'
  Bundler.require
rescue LoadError
end

Motion::Project::App.setup do |app|
  # Use `rake config' to see complete project settings.
  app.name = 'hellworld'

  app.frameworks += [
      'AVFoundation'
  ]

end

【问题讨论】:

    标签: ios avfoundation rubymotion


    【解决方案1】:

    看起来您使用的模式只是缺少“Flash”或“Torch”部分。我能找到的两个是:

    AVCaptureFlashModeOn
    AVCaptureTorchModeOn
    

    其中一个应该可以工作。

    https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009520-CH1-DontLinkElementID_2

    【讨论】:

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