简体   繁体   中英

iPhone App gets Hang/Blocks the UI for few seconds while coming in foreground from background

I have a very complex application which contains almost all UI parts. Now the problem is when I make my application in background and again comes in foreground, My UI gets blocked/Hangs for few seconds.

JFYI. This issue is on both Simulator as well as on Device.

Can anyone guide for this issue?? How to handle the app when coming in foreground??

Is it that my app contains so many UI parts and needs to reinitialize everything?? Or is there any iOS specific handling??

I have heard that iOS serializes and de-serializes the objects when going background and foreground. Please provide some guided links or so.. thanks

EDIT:

if(isInActive)
    {
        if([UIApplication sharedApplication].applicationIconBadgeNumber != 0)
        {
            //User canceled the Notification alert but badge is still there which indicates that
            //the push notification had arrived...
            [self performSelector:@selector(handleNotification:) withObject:nil afterDelay:1.0]; //change: From 2.0 to 1.0
        }

        isInActive = NO;

        int curTime = (int)ceil([[NSDate date] timeIntervalSince1970]);
        int storedTime;
        int timeDiff;
        storedTime = [[NSUserDefaults standardUserDefaults] integerForKey:@"logOffDuration"];
        if(storedTime > 0)
        {
            timeDiff  = curTime - storedTime;
            int delay = [[LogOffMgr getInstance].LogOff.delay_ intValue]/1000;
            if(timeDiff > delay)
            {
                [[LogOffMgr getInstance] stop];
                [[LogOffMgr getInstance] LogOffTimer_tick];
            }
        }
    }

I am not sure but from your code, I can only think

[self performSelector:@selector(handleNotification:) withObject:nil afterDelay:1.0];

may be blocking your UI. I think that it executes your DidBecomeActive method and then after a seconds delay it starts execution of handleNotification . So use performSelectorInBackground if possible ie if you don't do any user interface related changes in handleNotification: .

[self performSelectorInBackground:@selector(handleNotification:) withObject:nil];

Hope this helps.

Let me know if you need more help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM