飞行模式下的Rubymotion / bubblewrap geolocation会导致应用程序崩溃 [英] Rubymotion / bubblewrap geolocation in airplane mode makes the app crash

查看:129
本文介绍了飞行模式下的Rubymotion / bubblewrap geolocation会导致应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在某些应用中获得干净的geoloc实现;
相当困扰bubblewrap为场所提供的限制

  def get_location 
begin
BW :: Location.get_once do | location |
如果位置
self.latitude = location.latitude
self.longitude = location.longitude
end
end
rescue
putscan 't geoloc
end
end

显示'测试' - 我期望 - 会用ruby代码作为回退),如果我在手机上设置飞行模式,我只会遇到一个简单的应用程序崩溃。

谢谢如果有任何经验,使它在这种模式下工作

解决方案

我相信地理位置的东西运行在一个单独的线程,所以你会希望将您的开始/救援代码放在块中:

  BW :: Location.get_once do | location | 
开始
如果位置
self.latitude = location.latitude
self.longitude = location.longitude
end
rescue
putscan 't geoloc'
end
end

然而,Bubblewrap会让你真的通过将 location 设置为具有一个值的散列, {error:type} ,知道是否有错误。由于您使用的是 get_once ,所以返回值可以是 Hash CLLocation 对象,因此您需要检查对象类型以避免错误:

  BW :: Location.get_once do | location | 
if location.is_a?(Hash)&& location [:error]
putscan not geoloc
else
self.latitude = location.latitude
self.longitude = location.longitude
end
结束


Trying to get an clean geoloc implementation in some app; quite struggling with the limitations of what bubblewrap provide for locations

   def get_location
        begin
          BW::Location.get_once do |location|
            if location
              self.latitude   = location.latitude
              self.longitude  = location.longitude
            end
          end
        rescue
          puts "can't geoloc"
        end
      end

With this code (sorry bu I show the 'tests' that - i expect - would work as fallbacks with ruby code), I just get a plain app crash if i set the airplane mode on the phone

Thanks if any experiences on making it works in this mode

解决方案

I believe the geolocation stuff runs in a separate thread, so you would want to put your begin/rescue code within the block:

BW::Location.get_once do |location|
  begin
    if location
      self.latitude   = location.latitude
      self.longitude  = location.longitude
    end
  rescue
    puts "can't geoloc"
  end
end

However, Bubblewrap will actually let you know if there was an error by setting location to a hash with one value, {error: type}. Since you're using get_once, the return value could be either a Hash or a CLLocation object, so you do need to check the object type to avoid an error:

BW::Location.get_once do |location|
  if location.is_a?(Hash) && location[:error]
    puts "can't geoloc"
  else
    self.latitude   = location.latitude
    self.longitude  = location.longitude
  end
end

这篇关于飞行模式下的Rubymotion / bubblewrap geolocation会导致应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆