mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
Merge pull request #118 from GantMan/ios_version_detection
neato iOS version detection
This commit is contained in:
@@ -17,6 +17,19 @@ module RubyMotionQuery
|
||||
@_ios_eight ||= screen.respond_to?(:coordinateSpace)
|
||||
end
|
||||
|
||||
# Find out what version of iOS you're using.
|
||||
# `rmq.device.is_version? 8`
|
||||
# `rmq.device.is_version? "7.1"`
|
||||
#
|
||||
# @return [Boolean]
|
||||
def is_version? version
|
||||
!!ios_version.match("^#{version}")
|
||||
end
|
||||
|
||||
def ios_version
|
||||
UIDevice.currentDevice.systemVersion
|
||||
end
|
||||
|
||||
# @return [UIScreen]
|
||||
def screen
|
||||
UIScreen.mainScreen
|
||||
|
||||
@@ -31,6 +31,21 @@ describe 'device' do
|
||||
rmq.device.should == RubyMotionQuery::Device
|
||||
end
|
||||
|
||||
it 'can detect what iOS version is in use' do
|
||||
rmq.device.ios_version.should == UIDevice.currentDevice.systemVersion
|
||||
#validate this is numbers and dots
|
||||
rmq.device.ios_version.match(/^(\d|\.)+$/).should.not == nil
|
||||
end
|
||||
|
||||
it 'lets you know if a queried version of iOS is correct' do
|
||||
current_version = rmq.device.ios_version
|
||||
rmq.device.is_version?(current_version).should == true
|
||||
# fail condition
|
||||
rmq.device.is_version?(2).should == false
|
||||
# can check with just major version number like 7 for "7.1"
|
||||
rmq.device.is_version?(current_version[0]).should == true
|
||||
end
|
||||
|
||||
it 'should have a screen' do
|
||||
@rmq.device.screen.should == UIScreen.mainScreen
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user