multithreading - iOS Accessing UIScreen on Background Thread -
i have method in charge of loading details events (queries sqlite database titles, descriptions, thumbnail paths, etc.) that, since need call large amount of events, dispatching background thread using grand central dispatch.
the problem getting uikit thread exception (letting me know i'm running ui methods on thread other main thread, causing app crash). i'm not changing ui @ impossible find, narrowed down 1 line of code:
bool retina = (uiscreen.mainscreen.scale > 1.0); i using uiscreen determine if device has retina screen (to determine if thumbnail image path should have "@2x" appended @ end) , accessing (what appears static variable) throws uikit exception.
is there work-around determining if screen retina doesn't use uikit (or background-thread safe), or there better way figure out?
note: i'm using xamarin (c#) create app, answer in swift fine , easy convert.
first, don't have specify @2 when opening images display on screen. ios selects correct version uiimage(named: "basename").
but if need here swift code:
func isretina() -> bool { var scale: cgfloat = 0.0 dispatchqueue.main.sync { scale = uiscreen.main.scale } return scale > 1.0 } because use in many place, consider putting in utility/base class.
Comments
Post a Comment