ios - What could be causing this code to NOT allow re-entry into springboard? -
i have app uploads images bunch of places @ once, kinda instagram style.
it setup nsoperationqueue
runs bunch of nsoperation
wrappers around an asynchronous nsurlconnection
.
most questions begin end in "the callbacks don't called because calling thread joined before return. not kind of question. am getting callbacks expected, somehow preventing app backgrounding when home button pressed. thought not able blocked @ due sandboxing, somehow have done it. pressing home button while operations running nothing until complete, @ point (20-30sec later) app backgrounds.
**nb seems happen on single core processor devices. can reproduce on iphone 4, not 4s or ipad 3.*
still interested? here setup:
self.uploadqueue = [[nsoperationqueue alloc] init]; [self.uploadqueue setmaxconcurrentoperationcount:1]; [self.uploadqueue setsuspended:yes];
later on, add operations queue , unsuspend start. here code nsoperation
subclasses:
- (bool)isconcurrent { return yes; } - (bool)isexecuting { return self.executing; } - (bool)isfinished { return self.finished; } - (void)start { // omitted: check cancel... // omitted: check if setup run [self willchangevalueforkey:@"isexecuting"]; self.executing = yes; [self didchangevalueforkey:@"isexecuting"]; [self.sharer share]; cfrunlooprun(); } - (void)completeoperation { [self willchangevalueforkey:@"isfinished"]; [self willchangevalueforkey:@"isexecuting"]; self.executing = no; self.finished = yes; [self didchangevalueforkey:@"isexecuting"]; [self didchangevalueforkey:@"isfinished"]; cfrunloopstop(cfrunloopgetcurrent()); }
the share
method sets asynchronous nsurlconnection
, fires off so:
- (void)share { // omitted: connection setup [nsurlconnection sendasynchronousrequest:postrequest queue:[nsoperationqueue mainqueue] completionhandler:^(nsurlresponse *response, nsdata *responsedata, nserror *error){ // handle error or success, call [self.currentoperation completeoperation]; }];
aside side-effect trying solve for, code works in supposed to, callbacks called, threads stay alive long need to, , operation queue runs specified number of operations @ time.
what have tried? tried:
- calling nsurlconnection on
[nsoperationqueue currentqueue]
. caused async connection not callback block. - forcing each nsoperation onto main thread in
start
method. did not solve problem, caused code sometime not work , ui freeze. - implementing own queue mutable array , gcd on right dispatch thread. couldn't work.
- synchronous nsurlconnections in operations. didn't try because not option me. of network frameworks such facebook ios sdk not have synchronous option.
pausing execution during time after home-button press, before operations done yields nothing interesting. there doesn't seem on main thread waiting lock or execution finish.
am setting complete bozo? going on here , how can fix it?
edit:
turns out networking stuff red herring. looping caanimations preventing return springboard somehow.
original guesses:
my guess: shouldn't calling cfrunlooprun
in start method; start method of concurrent operation expected return before operation complete , finish later. you're holding on gcd lock (thread?) system needs dispatch other tasks.
if need monopolize thread via cfrunlooprun
, should kick off own thread in start
, return. think easier, though, not use nsoperation , kick off (already async) url connections main thread, keeping array of things share when each 1 finished.
actually, think problem cfrunloopstop(cfrunloopgetcurrent())
: you're running on main thread, you're stopping main run loop!
Comments
Post a Comment