Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 21, 2013, 06:35 PM   #1
RookieAppler
macrumors member
 
Join Date: Mar 2012
Alert view blocked by background thread and preventing it to show on screen

I have a method that gets launched by a UIBarbuttonitem click. In that the first step is launch a alert view. Then a background thread starts to pull data from web service. I made sure that alert view is shown on main thread by using performselectoronmainthread. But still there is a 13 second delay from when i click the barbutton click and showing of alert view. Here is the code.


Code:
- (void)refreshDataAction
{
 
	//Put up an alert box indicating user to wait while data is loading.
	
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Data is Loading"
													message:@"Please wait while data is being refreshed."
												   delegate:self
										  cancelButtonTitle:@"OK"
										  otherButtonTitles:nil, nil];
 
	[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:FALSE];
	
	NSLog(@"Refresh Data");
	self.txtCustomerSearch.text =@"";
	[self cleanUPPreviousLabels];

	
	NSLog(@"hit in willpresenet alertview at 221");
	self.refreshActIndicator.hidden = NO;
	[self.refreshActIndicator startAnimating];
	NSLog(@"Dispatching");

	//Disable the view and all the other controls
	self.txtCustomerSearch.userInteractionEnabled =NO;
	self.txtCustomerSearch.enabled =NO;
	self.btnSearch.enabled =NO;
	self.btnSearch.userInteractionEnabled = NO;
	self.scrollView.userInteractionEnabled = NO;
	//self.view.userInteractionEnabled =NO;
	self.chkButton.enabled = NO;
	
	
	[self deletePreviousValues];
	dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
		NSLog(@"Getting customer values");
		[self getAllCustomerValues];
		NSLog(@"Got customer values");
		
		NSError *nwerror = nil;
		if (![self.secondMOC save:&nwerror])
		{
			NSLog(@"209 Failed to save second MOC");
		}
		else
		{
			//NSLog(@"saved success");
		}
		
		
		self.txtCustomerSearch.userInteractionEnabled = YES;
		self.txtCustomerSearch.enabled =YES;
		self.btnSearch.enabled =YES;
		self.btnSearch.userInteractionEnabled = YES;
		self.scrollView.userInteractionEnabled = YES;
		self.view.userInteractionEnabled =YES;
		self.chkButton.enabled = YES;
		
		[self.refreshActIndicator stopAnimating];
	 
		NSLog(@"Saved");
		
		
	});
	NSLog(@"Dispatched");	
}
Why is alert view not showing up immediately. OR Why is my UIThread( i am assuming my main thread) not showing the alertview immediately. Any help would be great. I am trying to get to solve this past 5 hours. So please help. It is in iOS 6.0 and iPad in-house project. If you need more information, please ask. Thanks.
RookieAppler is offline   0 Reply With Quote
Old Feb 21, 2013, 07:16 PM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
How long does this line take to execute?:
Quote:
[self deletePreviousValues];
Because it's outside your background thread.

P.S. You don't need to use performSelectorOnMainThread: if refreshDataAction is already running on the main thread.
__________________
dejo is offline   0 Reply With Quote
Old Feb 21, 2013, 08:32 PM   #3
RookieAppler
Thread Starter
macrumors member
 
Join Date: Mar 2012
@dejo. That is an excellent observation. That method was the culprit. It took 13 seconds.
So i put it in another background like this

Code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
			[self deletePreviousValues];
		NSLog(@"Deletion done");
	});
...and other code continues like this
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
		NSLog(@"Getting customer values");
                [self getAllCustomerValues];
		NSLog(@"Got customer values");
.....
I want to be absolutely sure that deletePreviousValues is completed first and then only getAllCustomerValues gets called. But my simulator output is like this

Quote:
Dispatching
Dispatched
Getting customer values
Deletion done
So i want "Deletion done" to be done before "Getting customer values" starts. I gave HIGH priority but still it is not getting done. Also sometimes it exceptions. What is the correct way?

The exception is like this

Quote:
malloc: *** error for object 0x9254e04: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug

Last edited by RookieAppler; Feb 21, 2013 at 09:46 PM. Reason: Added exception explanation
RookieAppler is offline   0 Reply With Quote
Old Feb 21, 2013, 10:11 PM   #4
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by RookieAppler View Post
@dejo. That is an excellent observation. That method was the culprit. It took 13 seconds.
So i put it in another background like this
Why put it in another background thread? Why not put it in the existing background thread? You want deletePreviousValues to be completed before calling getAllCustomerValues, then call them sequentially.
__________________
dejo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
alerts, background, ios, launch, nsthread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
So Background App Refresh only works for apps in the multitask view, correct? DramaLLama iOS 7 63 Mar 20, 2014 01:40 PM
Change "show item info" in Finder icon view to show size of folder instead of items? drought OS X Mavericks (10.9) 2 Jan 17, 2014 11:52 PM
Lock screen-today view-calender. List view? starstreak iOS 7 5 Sep 18, 2013 09:39 PM
Any tips for preventing Bumper from peeling up screen/back protector? KittyKatta iPhone Accessories 1 Oct 10, 2012 10:30 AM

Forum Jump

All times are GMT -5. The time now is 06:07 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC