我在Rubymotion中執行一個相當的香草調度隊列,但它顯然早退了。它永遠不會超過initWithContentsOfURL調用。但是,刪除Dispatch :: Queue包裝並將調用放入主線程中。Rubymotion調度退出提前
模擬器中的應用程序退出時沒有堆棧跟蹤或指示出了什麼問題。我錯在使用調度隊列嗎?
def foo
Dispatch::Queue.concurrent.async do
error_ptr = Pointer.new(:object)
data = NSData.alloc.initWithContentsOfURL(
NSURL.URLWithString(url), options:NSDataReadingUncached, error:error_ptr)
unless data
p error_ptr[0]
return
end
json = NSJSONSerialization.JSONObjectWithData(data, options:0, error:error_ptr)
unless json
presentError error_ptr[0]
return
end
Dispatch::Queue.main.sync { print_results(json) }
end
end
def print_results(json)
p "#{json}"
end
您的代碼顯示'print_results'方法與您的'Dispatch'調用內嵌 - 它是真的這樣設置,還是包含在不同方法中的'Dispatch'調用? –
它沒有內聯。這是一個單獨的電話。調度應該包含在一個方法中。 – nathasm
那麼你的代碼在RubyMotion 1.8上對我完全適用;也許這是你想加載的具體URL的問題? –