methods - iOS cancel (void)-execution and dismiss ViewController -
i want cancel long running calculation method , dismiss viewcontroller when app send background.
details: after button action in mainviewcontroller new resultviewcontroller shown , long running calculation method started in viewdidload method. calculation method running on main thread totally fine.
for case app going background want prevent app killed due not finished calculation method. set applicatindidenterbackground notification used in resultviewcontroller don't know how cancel running calculation method , dismiss resultviewcontroller.
thanks.
and long running calculation method started in viewdidload method. calculation method running on main thread totally fine.
honesty, doubt can labelled 'fine'.
proper solution move these calculations background thread , execute them asynchronously.
if block main thread long (like in case) won't know app going put background - notification won't processed app's main queue since consume of resources. watchdog kill application since cannot process applicatindidenterbackground
notification within reasonable amount of time (approximately 7-8 seconds).
edit (in response question in comment)
you may want check out how implement nsoperation
, how use nsoperationqueue
. resource example this site.
what i'm telling general idea how cancellation of operations work - usage of iscancelled
property, checked in critical sections of operation (and used stop computations). don't have implement nsoperation in case (unless want - may exercise ;-) ) if create class processing data, , add method cancel
in it, can imitate nsoperation's
behavior in code.