我目前正在用自己的方式进入RubyMotion,并尝试使用iPhone的相机手电筒。我已经在我的Rakefile中“导入”了AVFoundation框架,但似乎有些地方不对劲。你知道有没有更简单的方法处理这个问题的gem?我看过rubymotion-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发布于 2014-03-21 13:49:37
看起来你使用的模式只是缺少了“Flash”或“Torch”部分。我能找到的两个是:
AVCaptureFlashModeOn
AVCaptureTorchModeOn其中一个应该是有效的。
https://stackoverflow.com/questions/22538489
复制相似问题