ios - How do make background task complete when that view has been popped from the navigation stack -
_queue nsoperationqueue object. upload image server using following:
[_queue addoperationwithblock:^{ //post request used upload photo server //request has been configured before step nsdata *returndata = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil]; }];
this can take couple seconds , if press button on navigation controller connection closes , and image not upload. how can make background task occur if view controller popped navigation stack?
i know sendsynchronousrequest has been deprecated, fix eventually.
presumably _queue member variable of view controller? if quick fix things working change static member variable (to change lifetime), preferable move model class , have model upload image on behalf of view controller
leading better design, once becomes asynchronous - image scenario:
- view controller starts upload - user navigates view controller b - upload fails , need notify user of failure or retry upload - what? started upload no longer exists how notify user or retry upload?
if make model's responsibility upload image situation:
- view controller starts upload - user navigates view controller b - upload fails , need notify user or retry - model broadcasts notification upload has failed or retires upload - meta view controller listens notification , displays dialog user informing of failure
Comments
Post a Comment