【问题标题】:Rubymotion / bubblewrap geolocation in airplane mode makes the app crash飞行模式下的 Rubymotion / bubblewrap 地理定位使应用程序崩溃
【发布时间】:2014-03-20 10:58:47
【问题描述】:

尝试在某些应用中获得干净的 geoloc 实现; 非常挣扎于气泡包装为位置提供的限制

   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

使用此代码(抱歉,我展示了“测试”——我希望它可以作为 ruby​​ 代码的后备工作),如果我在手机上设置飞行模式,我只会得到一个普通的应用程序崩溃

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

【问题讨论】:

    标签: ruby geolocation rubymotion


    【解决方案1】:

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

    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
    

    但是,Bubblewrap 实际上会通过将location 设置为具有一个值{error: type} 的散列来让您知道是否存在错误。由于您使用的是get_once,因此返回值可能是HashCLLocation 对象,因此您需要检查对象类型以避免错误:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-15
      • 1970-01-01
      • 2018-10-30
      • 2017-10-14
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多