ios - How to Syncronize async data download with the main thread in swift -
i have problem. when app start, downloads async data server in app delegate, segue home screen. in home screen, app checks async data have been downloaded in app delegate. if doesn't find data, loads offline content, because data maybe not ready yet or maybe server down , app never data.
my problem comes when app download data after offline data has been loaded. home screen loaded offline data, mixed new data.
in app delegate i've set download async data in core location delegate method, because data downloaded if user grants location access app:
func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]){ if(hasbeenlaunched == false){ hasbeenlaunched = true dispatch_async(dispatch_get_main_queue()){ self.loadcityslugarray() } } //other code... }
i set hasbeenlaunched
bool true when app has entered download method, , check in home screen:
override func viewdidload() { if(hasbeenlaunched == false){ //async data hasn't been downloaded server //load data work offline or without location access let appdelgte = appdelegate() appdelgte.loadofflineslug() } else//need download home screen image { //download home screen image sethomescreenimage() } }
i've tried put sleep before bool check, it's no useful because async data not downloaded when sleep active.
var seconds = 0 repeat{ sleep(1) seconds += 1 if(seconds >= 5){break} }while hasbeenlaunched == false
any 1 knows how that?
Comments
Post a Comment