ios - Run code in the background -
this question has answer here:
i'm trying download image website , save uiimage if user has low connection can take forever... how can download in background user can keep using app in meantime?
here code:
theicon.image = [[uiimage alloc] initwithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://mywebsite.com/icon.png"]]];
use gcd.
dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_background, 0), ^{ // background code dispatch_async(dispatch_get_main_queue(), ^{ // handling on main thread when done! }); });
Comments
Post a Comment