diff --git a/motion/ruby_motion_query/device.rb b/motion/ruby_motion_query/device.rb index cb657a6..bcd50eb 100644 --- a/motion/ruby_motion_query/device.rb +++ b/motion/ruby_motion_query/device.rb @@ -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 diff --git a/spec/device.rb b/spec/device.rb index 66b5b58..8f08505 100644 --- a/spec/device.rb +++ b/spec/device.rb @@ -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