ios - ImagePicker Camera only loads when in background thread - else it's a black screen -
i have tab-based app 2 tabs: first 1 performs multiple operations in background thread (downloading json) , updates ui on main thread when fetching over. second tab presents camera appears. when open app, fetching starts in background in tab #1. if switch tab #2 while in background thread in tab 1, camera loads. if wait until main thread updated ui (still tab 1) before switching tab 2, camera takes 10 seconds load, showing black screen. what's more weird nslogs tell me camera supposed loaded, black screen shows up. question is, there way "clear" main thread when tab #2 appears, or better, there way show camera high priority task in main thread?
this code in viewdidappear (tab 2):
dispatch_async(dispatch_get_main_queue(), ^{ nslog(@"4"); [self showimagepickerforsourcetype:uiimagepickercontrollersourcetypecamera]; }); next:
- (void)showimagepickerforsourcetype:(uiimagepickercontrollersourcetype)sourcetype { nslog(@"5"); dispatch_async(dispatch_get_main_queue(), ^{ nslog(@"6"); [[uiapplication sharedapplication] setstatusbarhidden:yes]; if ([uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) { nslog(@"7"); imagepickercontroller = [[uiimagepickercontroller alloc] init]; imagepickercontroller.modalpresentationstyle = uimodalpresentationcurrentcontext; imagepickercontroller.sourcetype = sourcetype; imagepickercontroller.delegate = self; imagepickercontroller.showscameracontrols = no; // nslog(@"here"); if (isiphone5) { nslog(@"8"); [[nsbundle mainbundle] loadnibnamed:@"overlayview" owner:self options:nil]; } else { nslog(@"not 5"); [[nsbundle mainbundle] loadnibnamed:@"over2" owner:self options:nil]; } self.overlayview.frame = imagepickercontroller.cameraoverlayview.frame; imagepickercontroller.cameraoverlayview = self.overlayview; self.overlayview = nil; self.imagepickercontroller = imagepickercontroller; [self presentviewcontroller:self.imagepickercontroller animated:no completion:nil]; nslog(@"9 done"); } }); }
seeing log output doesn't mean camera view visible, hence why there completion block provided in presentviewcontroller:animated:completion: method. have tried putting code there see when that's run?
this kind of problem time profiler tool in instruments designed for. if haven't already, highly suggest investigating tool, can pinpoint what's causing lag in app.
Comments
Post a Comment