I need to pass 2 NSDictionary from a ViewController to another ViewController, My App some times pass the data ok, but, another times, data don't reach to second ViewController.
I need consult a web service twice, that web service response is a JSON, this JSON (2) is what I need pass to other ViewController
The call to web service is made here (in dispatch_async):
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t) (delayInSeconds * NSEC_PER_SEC));
dispatch_queue_t queue = dispatch_queue_create("com.micrologica.modules", nil);
dispatch_async(queue, ^{
urlConsultarDisponibilidad = [NSString stringWithFormat:connectionUrl getAvailableModuleListAPI, fechaDiaUno, idLocal, idServicioUno, idProfesionalUno, idServicioDos, idProfesionalDos];
[FunctionsAmano setConnectionAndRequest:urlConsultarDisponibilidad completion:^(NSDictionary *dataResponse) {
NSLog(#"response dia 1: %#", dataResponse);
if(dataResponse) {
NSString *resp = [NSString stringWithFormat:#"%#", [dataResponse objectForKey:#"resp"]];
if([resp isEqualToString:#"1"]) {
NSLog(#"almost finish 1");
modulesDiaUno = [dataResponse objectForKey:#"data"];
}
dispatch_after(popTime, queue, ^(void){
finishedDiaUno = YES;
NSLog(#"finished 1");
});
}
}];
});
dispatch_async(queue, ^{
urlConsultarDisponibilidad = [NSString stringWithFormat:connectionUrl getAvailableModuleListAPI, fechaDiaDos, idLocal, idServicioUno, idProfesionalUno, idServicioDos, idProfesionalDos];
[FunctionsAmano setConnectionAndRequest:urlConsultarDisponibilidad completion:^(NSDictionary *dataResponse) {
NSLog(#"response dia 2: %#", dataResponse);
if(dataResponse) {
NSString *resp = [NSString stringWithFormat:#"%#", [dataResponse objectForKey:#"resp"]];
if([resp isEqualToString:#"1"]) {
NSLog(#"almost finish 2");
modulesDiaDos = [dataResponse objectForKey:#"data"];
}
dispatch_after(popTime, queue, ^(void){
finishedDiaDos = YES;
NSLog(#"finished 2");
});
}
}];
});
dispatch_async(queue, ^{
dispatch_async(dispatch_get_main_queue(), ^{
BOOL exito = YES;
int segundos = 0;
/* Si la consulta se demora mas de 60 segundos, se interrumpe e informa al usuario de un problema */
while (!finishedDiaUno && !finishedDiaDos) {
[NSThread sleepForTimeInterval:1];
if(segundos >= 60) {
exito = NO;
break;
}
segundos++;
}
if(exito) {
HorariosViewController *horariosView = [self.storyboard instantiateViewControllerWithIdentifier:#"ModulesView"];
horariosView.modulesDiaUno = self.modulesDiaUno;
horariosView.modulesDiaDos = self.modulesDiaDos;
double delayInSeconds = 4.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t) (delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self presentViewController:horariosView animated:NO completion:nil];
});
}
});
});
This code is working fine, but, some times the response (dataResponse) comes after I make change of ViewController, I don't know why changes ViewController if the dataResponse not came.
How to you see, I instantiate of the second ViewController, I set the data, and change the ViewController on a dispatch_after (4.0 seconds).
Why I change the ViewController in a dispatch_after? because, if I don't implement the dispatch_after, the NSDictionarys ALWAYS comes empty!, In this way, the NSDictionarys some times comes empty and some times comes ok.
Can you tell me why is wrong with my code?
PS: the dictionaries appear empties in the other ViewController (has no element, but is not null).
Here is a advice: don't block your main thread, don't call sleep on main thread.
It a concurrency problem , the method setConnectionAndRequest:urlConsultarDisponibilidad should be asynchronous and the UI code may execute before the two responses. I think it can be fixed like this:
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t) (delayInSeconds * NSEC_PER_SEC));
dispatch_queue_t queue = dispatch_queue_create("com.micrologica.modules", nil);
dispatch_async(queue, ^{
urlConsultarDisponibilidad = [NSString stringWithFormat:connectionUrl getAvailableModuleListAPI, fechaDiaUno, idLocal, idServicioUno, idProfesionalUno, idServicioDos, idProfesionalDos];
[FunctionsAmano setConnectionAndRequest:urlConsultarDisponibilidad completion:^(NSDictionary *dataResponse) {
NSLog(#"response dia 1: %#", dataResponse);
if(dataResponse) {
NSString *resp = [NSString stringWithFormat:#"%#", [dataResponse objectForKey:#"resp"]];
if([resp isEqualToString:#"1"]) {
NSLog(#"almost finish 1");
modulesDiaUno = [dataResponse objectForKey:#"data"];
}
dispatch_after(popTime, queue, ^(void){
finishedDiaUno = YES;
NSLog(#"finished 1");
if (finishedDiaDos) {
dispatch_async(dispatch_get_main_queue(), ^{
HorariosViewController *horariosView = [self.storyboard instantiateViewControllerWithIdentifier:#"ModulesView"];
horariosView.modulesDiaUno = self.modulesDiaUno;
horariosView.modulesDiaDos = self.modulesDiaDos;
[self presentViewController:horariosView animated:NO completion:nil];
});
}
});
}
}];
});
dispatch_async(queue, ^{
urlConsultarDisponibilidad = [NSString stringWithFormat:connectionUrl getAvailableModuleListAPI, fechaDiaDos, idLocal, idServicioUno, idProfesionalUno, idServicioDos, idProfesionalDos];
[FunctionsAmano setConnectionAndRequest:urlConsultarDisponibilidad completion:^(NSDictionary *dataResponse) {
NSLog(#"response dia 2: %#", dataResponse);
if(dataResponse) {
NSString *resp = [NSString stringWithFormat:#"%#", [dataResponse objectForKey:#"resp"]];
if([resp isEqualToString:#"1"]) {
NSLog(#"almost finish 2");
modulesDiaDos = [dataResponse objectForKey:#"data"];
}
dispatch_after(popTime, queue, ^(void){
finishedDiaDos = YES;
NSLog(#"finished 2");
if (finishedDiaUno) {
dispatch_async(dispatch_get_main_queue(), ^{
HorariosViewController *horariosView = [self.storyboard instantiateViewControllerWithIdentifier:#"ModulesView"];
horariosView.modulesDiaUno = self.modulesDiaUno;
horariosView.modulesDiaDos = self.modulesDiaDos;
[self presentViewController:horariosView animated:NO completion:nil];
});
}
});
}
}];
});
Related
I have 2 View Controllers Home and Home Details. In Home I have a table view in which I am showing thumbnail and duration of a video. When I click on a particular row it's details are shown in Home Details. On returning back I am updating that selected row. So for that in viewWillDisappear Method of Home Details I have written following code :
if ([self.delegate respondsToSelector:#selector(changeSelectedBucketData:)]) {
[self.delegate changeSelectedBucketData:_videoId];
}
Now in the Home Controller I have defined that method as:
-(void)changeSelectedBucketData:(NSString*)videoId {
NSString *dataStr = [NSString stringWithFormat:#"%#bucket_id=%#",kGetBucketById,videoId];
[[WebServiceCall sharedInstance] sendGetRequestToWebWithData:dataStr success:^(NSDictionary *json) {
if([[json valueForKey:#"ResponseCode"] integerValue] == 0) {
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[_arrayOfContent replaceObjectAtIndex:selectedIndex withObject:[json valueForKey:#"GetData"]];
if (_arrayOfContent.count) {
TableViewCellHome *cell = [self.mTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0]];
[self fillDataForIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0] forCell:cell];
}
});
}
} failure:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
});
}];
}
-(void)fillDataForIndexPath:(NSIndexPath*)indexPath forCell:(TableViewCellHome*)cell{
NSDictionary *dict = [_arrayOfContent objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:[[_arrayOfContent objectAtIndex:indexPath.row] valueForKey:#"video_URL"]];
[self downloadDurationAtURL:url cellTag:indexPath];
}
Now I have used the following code to Download Duration of a video :
- (NSUInteger)videoDuration:(NSURL *)videoURL {
AVURLAsset *videoAVURLAsset = [AVURLAsset assetWithURL:videoURL];
CMTime durationV = videoAVURLAsset.duration;
return CMTimeGetSeconds(durationV);
}
- (NSString *)videoDurationTextDurationTotalSeconds:(NSUInteger)dTotalSeconds {
NSUInteger dHours = floor(dTotalSeconds / 3600);
NSUInteger dMinutes = floor(dTotalSeconds % 3600 / 60);
NSUInteger dSeconds = floor(dTotalSeconds % 3600 % 60);
if (dHours > 0) {
return [NSString stringWithFormat:#"%i:%02i:%02i",dHours, dMinutes, dSeconds];
} else {
return [NSString stringWithFormat:#"%02i:%02i",dMinutes, dSeconds];
}
}
-(void)downloadDurationAtURL:(NSURL *)videoURL cellTag:(NSIndexPath*)indexPath {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//retrive image on global queue
NSUInteger dTotalSeconds = [self videoDuration:videoURL];
NSLog(#"dTotalSeconds %i",dTotalSeconds);
if (dTotalSeconds > 0) {
NSString *videoDurationText = [self videoDurationTextDurationTotalSeconds:dTotalSeconds];
dispatch_async(dispatch_get_main_queue(), ^{
TableViewCellHome *cell = [self.mTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];
[[_arrayOfContent objectAtIndex:indexPath.row] setObject : videoDurationText forKey:#"duration"];
cell.labelDuration.text = videoDurationText;
cell.labelDuration.hidden = false;
});
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
TableViewCellHome *cell = [self.mTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];
[[_arrayOfContent objectAtIndex:indexPath.row] setObject : #"" forKey:#"duration"];
cell.labelDuration.hidden = true;
cell.labelDuration.text = #"";
});
}
});
}
Now problem is that UI is getting blocked until the duration is changed in the cell. I am not able to select a particular row until duration is displayed on the cell. But it is working fine when I display the Home controller for the first time after calling the API. It only gets blocked when I call it from Home detail.
You need to load the duration asynchronously, like this:
- (void)videoDuration:(NSURL *)videoURL completion:(void (^)(CMTime))durationCallback {
AVURLAsset *videoAVURLAsset = [AVURLAsset assetWithURL:videoURL];
[videoAVURLAsset loadValuesAsynchronouslyForKeys:#[ #"duration"] completionHandler:^{
NSError *error;
if([videoAVURLAsset statusOfValueForKey:#"duration" error:&error]) {
NSLog(#"error getting duration: %#", error);
durationCallback(kCMTimeZero); // or something
} else {
durationCallback(videoAVURLAsset.duration);
}
}];
}
I'm trying to run some intensive processes serially, with multiple serial queues. The code is working, however my UI update doesn't occur, even though the method is called.
Here is the code that runs several processes serially.
- (void)importProcess {
dispatch_queue_t serialQueue = dispatch_queue_create("com.cyt.importprocessqueue", DISPATCH_QUEUE_SERIAL);
NSLog(#"checking image sizes");
__block NSMutableArray *assets;
dispatch_sync(serialQueue, ^() {
assets = [self checkImageSizes];
});
dispatch_sync(serialQueue, ^() {
[self appendLogToTextView:[NSString stringWithFormat:#"%i screenshot(s) ignored due to invalid size.",(int)(self.assets.count-assets.count)]];
if(assets.count==0) {
[self showNoRunesFoundAlert];
}
else {
[self appendLogToTextView:#"Preparing to process screenshots..."];
self.assets = [NSArray arrayWithArray:assets];
}
});
NSLog(#"processing uploads");
dispatch_sync(serialQueue, ^() {
[self processUploads];
});
NSLog(#"recognizing images");
dispatch_sync(serialQueue, ^() {
[self recognizeImages];
});
NSLog(#"recognizing images");
dispatch_sync(serialQueue, ^() {
[self processRuneText];
});
//dispatch_sync(dispatch_get_main_queue(), ^ {
//});
}
Within checkImageSizes, I have another serial queue:
- (NSMutableArray *)checkImageSizes {
dispatch_queue_t serialQueue = dispatch_queue_create("com.cyt.checkimagesizequeue", DISPATCH_QUEUE_SERIAL);
NSMutableArray *assets = [NSMutableArray new];
for(int i=0;i<self.assets.count;i++) {
dispatch_sync(serialQueue, ^{
PHAsset *asset = (PHAsset *)self.assets[i];
if(asset.pixelWidth==self.screenSize.width && asset.pixelHeight==self.screenSize.height) {
[assets addObject:asset];
NSString *logText = [NSString stringWithFormat:#"Screenshot %i/%i size is OK.",i+1,(int)self.assets.count];
[self performSelectorOnMainThread:#selector(appendLogToTextView:) withObject:logText waitUntilDone:YES];
}
else {
[self appendLogToTextView:[NSString stringWithFormat:#"ERROR: Screenshot %i/%i has invalid size. Skipping...",i+1,(int)self.assets.count]];
}
});
}
return assets;
}
The appendLogToTextView method is supposed to update the UI. Here is that code:
- (void)appendLogToTextView:(NSString *)newText {
dispatch_block_t block = ^ {
self.logText = [NSString stringWithFormat:#"%#\n%#", self.logText, newText];
NSString *textViewText = [self.logText substringFromIndex:1];
[UIView setAnimationsEnabled:NO];
if(IOS9) {
[self.textView scrollRangeToVisible:NSMakeRange(0,[self.textView.text length])];
self.textView.scrollEnabled = NO;
self.textView.text = textViewText;
self.textView.scrollEnabled = YES;
}
else {
self.textView.text = textViewText;
NSRange range = NSMakeRange(self.textView.text.length - 1, 1);
[self.textView scrollRangeToVisible:range];
}
[UIView setAnimationsEnabled:YES];
};
if ([NSThread isMainThread]) {
block();
}
else {
dispatch_sync(dispatch_get_main_queue(), block);
}
}
As you can see, I have tried calling appendLogToTextView both directly and using performSelectorOnMainThread. However, I'm not getting any updates to my text view, even though I confirm that the method is being called properly.
Interestingly, the UI updating works properly when I only use a single serial queue and use iteration counts to call the next method, as shown in the code below (_serialQueue is defined in viewDidLoad). However, I do not believe that implementation is good practice, as I'm wrapping serial queues within serial queues.
- (void)checkImageSizes {
NSMutableArray *assets = [NSMutableArray new];
for(int i=0;i<self.assets.count;i++) {
dispatch_async(_serialQueue, ^{
PHAsset *asset = (PHAsset *)self.assets[i];
if(asset.pixelWidth==self.screenSize.width && asset.pixelHeight==self.screenSize.height) {
[assets addObject:asset];
[self appendLogToTextView:[NSString stringWithFormat:#"Screenshot %i/%i size is OK.",i+1,(int)self.assets.count]];
}
else {
[self appendLogToTextView:[NSString stringWithFormat:#"ERROR: Screenshot %i/%i has invalid size. Skipping...",i+1,(int)self.assets.count]];
}
//request images
if(i==self.assets.count-1) {
[self appendLogToTextView:[NSString stringWithFormat:#"%i screenshot(s) ignored due to invalid size.",(int)(self.assets.count-assets.count)]];
if(assets.count==0) {
[self showNoRunesFoundAlert];
}
else {
[self appendLogToTextView:#"Preparing to process screenshots..."];
self.assets = [NSArray arrayWithArray:assets];
[self processUploads];
}
}
});
}
}
What am I not understanding about serial queues that is causing the UI updates in this version of the code to work, but my attempt at a "cleaner" implementation to fail?
In the end, I just ended up using dispatch groups and completion blocks in order to solve this problem.
I need to send a large amount of HTTP request in a for loop, and once I finish a task, I need to update progress on main thread.
float __block progress = 0.0f;
float __block tempValue = 0.0f;
dispatch_queue_t operationQueue = dispatch_queue_create("Operation Data", DISPATCH_QUEUE_CONCURRENT);
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
for (int uploadCount = 0; uploadCount < mutableArray.count; uploadCount++) {
dispatch_barrier_async(operationQueue, ^{
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
DDLogInfo(#"add Task.");
[MPRestAPI copyMediaToAlbum:mutableArray[uploadCount] targetAlbum:albumName success:^(BOOL bSuccess){
if (bSuccess) {
dispatch_async(dispatch_get_main_queue(), ^{
progress = (float)(uploadCount+1)/(float)mutableArray.count;
if(uploadCount+1 == mutableArray.count){
progressHUD.progress = 1.0;
[progressHUD hide:YES];
[self dismissViewControllerAnimated:NO completion:nil];
}else if(progress > tempValue) {
progressHUD.progress = progress;
tempValue = progress + 0.01;
}
});
}
}failure:^(NSError* error){
if(uploadCount == mutableArray.count -1){
[progressHUD hide:YES];
[self dismissViewControllerAnimated:NO completion:nil];
}
}];
});
dispatch_semaphore_signal(semaphore);
}
Then there comes low memory, and it crashed. and mutableArray.count can be 5000,so I wonder what should I do to fix this problem?
In my iOS app, I want to show the network activity indicator in the top status bar.
I've added the following:
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
But the activity indicator never appears.
Does anyone know what might be wrong?
Here is the full code:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
// load sets
[self loadSets];
}
-(void)loadSets{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"in loadSets");
// show loading animation
UIView *loadingView = loadingIndicator;
loadingView.center = CGPointMake(screenWidth/2, screenHeight/2);
[self.view addSubview:loadingView];
[loadingIndicator startAnimating];
self.userSets = [[NSMutableArray alloc]init]; // re-initialize userSets
dispatch_async(bgQueue, ^{
NSString *userURLString = [userBaseUrl stringByAppendingFormat:#"/%#.json?auth_token=%#", username, auth_token];
NSLog(#"userURLString %#", userURLString);
NSURL *userURL = [NSURL URLWithString:userURLString];
NSData * userData = [NSData dataWithContentsOfURL:userURL];
dispatch_async(dispatch_get_main_queue(), ^{
if(userData){
[self fetchSets:userData];
// remove loading animation
[loadingView removeFromSuperview];
}else{
// error with authentication - should log out and require relogin
// [self logoutClick];
}
});
});
});
}
-(void)fetchSets:(NSData *)responseData{
NSError * error;
NSDictionary * json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
if(json){
NSArray *sets = [json objectForKey:#"sets"];
for (NSDictionary *currentSet in sets){
Set *userSet = [[Set alloc] init];
userSet.name = [currentSet objectForKey:#"name"];
userSet.videoURL = [[currentSet objectForKey:#"media"] objectForKey:#"mp4"];
userSet.gifURL = [[currentSet objectForKey:#"media"] objectForKey:#"gif"];
userSet.imgURL = [[currentSet objectForKeyedSubscript:#"media"] objectForKey:#"img"];
userSet.setID = [currentSet objectForKey:#"id"];
[self.userSets addObject: userSet];
}
NSLog(#"trying to reload table data with userSets length %d", [self.userSets count]);
[self.collectionView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"done loading table data");
});
}
}
When I call "performSelectorInBackground" to process some action asynchronously.
My code struct is like:
[self performSelectorInBackground:#selector(AddTheAdditionalDataSourceToTableView) withObject:nil];
and AddTheAdditionalDataSourceToTableView's code struct is like :
-(void)AddTheAdditionalDataSourceToTableView
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
...
dispatch_async(dispatch_get_current_queue(), ^{
...
});
...
});
}
and after the viewController call 'popViewController', dealloc will never be called!!!
I know I can just call 'AddTheAdditionalDataSourceToTableView' directly. it will process asynchronously and it works fine. dealloc will called when the viewController did disappear.But I don't know why calling it using "performSelectorInBackground" will cause this exception above.
: (
- (void)reloadTableViewDataSource
{
// should be calling your tableviews data source model to reload
// put here just for demo
[self performSelectorInBackground:#selector(reFreshTableView) withObject:nil];
//[self reFreshTableView];
}
- (void)reFreshTableView
{
NSString *myPoint = [self currentLocationPoint];
if (!myPoint || [myPoint isEqualToString:#""]) {
[self enableButtons];
[tableView tableViewDidFinishedLoading];
return;
}
Interface *interface = [[Interface alloc]init];
/* 默认从page 1开始刷新数据 */
[self disableButtons];
_interface = (id)interface;
interface.delegate = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[interface aroundInfoFromServiceInterface:_distanceType
withTableType:_tableType
withSortType:_sortType
withPageNum:1
withNumPerPage:NumberOfCellInOneRequest withPoint:myPoint];
});
//[interface release];
//[tableView flashMessage:#"hahahah"];
}
- (void)aroundInfoFromServiceInterface:(NSInteger)distance
withTableType:(NSInteger)tableType
withSortType:(NSInteger)sortType
withPageNum:(NSInteger)pageNum
withNumPerPage:(NSInteger)numPerPage
withPoint:(NSString *)myPiont
{
RequestData *data1 = [RequestData requestData:[NSString stringWithFormat:#"%d", distance] key:#"aroundDistant"];
RequestData *data2 = [RequestData requestData:[NSString stringWithFormat:#"%d", tableType] key:#"itemType"];
RequestData *data3 = [RequestData requestData:[NSString stringWithFormat:#"%d", sortType] key:#"sortType"];
RequestData *data4 = [RequestData requestData:[NSString stringWithFormat:#"%d", pageNum] key:#"pageNum"];
RequestData *data5 = [RequestData requestData:[NSString stringWithFormat:#"%d", numPerPage] key:#"numPerPage"];
RequestData *data6 = [RequestData requestData:[NSString stringWithFormat:#"%#", myPiont] key:#"mappoint"];
NSLog(#"%# , %# , %# , %# , %# , %#" , [NSString stringWithFormat:#"%d", distance] ,[NSString stringWithFormat:#"%d", tableType] ,[NSString stringWithFormat:#"%d", sortType] , [NSString stringWithFormat:#"%d", pageNum], [NSString stringWithFormat:#"%d", numPerPage] , [NSString stringWithFormat:#"%#", myPiont]);
NSArray *tempArray = [NSArray arrayWithObjects:data1, data2, data3, data4, data5, data6, nil];
DataFromService *dataFromService = [[[DataFromService alloc]init]autorelease];
dispatch_async(dispatch_get_main_queue(), ^{
NSString *strContent = [dataFromService requestData:tempArray fromURL:tableType == 0?AROUND_FRIEND_INFO_URL:AROUND_FISHING_STORE_AND_AREA_INFO_URL];
NSArray *responseArray = (NSArray *)[self checkRequestResponse:strContent];
if (responseArray) {
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
switch (tableType) {
case TableType_FrinedsAround:
tempArray = [[FormatData shareInstance] formatDictToFriendsAround:responseArray];
break;
case TableType_FishingStoreAround:
tempArray = [[FormatData shareInstance] formatDictToFishingStoreAround:responseArray];
break;
case TableType_FishingAreaAround:
tempArray = [[FormatData shareInstance] formatDictToFishingAreaAround:responseArray];
break;
default:
break;
}
if (self.delegate && [self.delegate respondsToSelector:#selector(requestDataSuccess:responses:)]) {
[self.delegate requestDataSuccess:self responses:tempArray];
return;
}
}
});
}
dispatch_get_current_queue()
Gets a background queue, because you are using performSelectorInBackground, it gets called from a background queue.
dispatch_get_main_queue()
dispatch_async returns immediately, so you don't need to use performSelectorInBackground:. You can just call dispatch_async directly:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
...
dispatch_async(dispatch_get_main_queue(), ^{
...
});
...
});