簡體   English   中英

iPhone App 從后台進入前台時掛起/阻塞 UI 幾秒鍾

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

我有一個非常復雜的應用程序,其中幾乎包含所有 UI 部分。 現在的問題是當我在后台創建我的應用程序並再次進入前台時,我的UI阻塞/掛起幾秒鍾。

僅供參考。 這個問題在模擬器和設備上都有。

任何人都可以指導這個問題嗎? 進入前台時如何處理應用程序?

是不是我的應用程序包含如此多的 UI 部分並且需要重新初始化所有內容?? 或者有什么iOS具體處理嗎??

我聽說 iOS 在后台和前台時序列化和反序列化對象。 請提供一些指導鏈接等等..謝謝

編輯:

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];
            }
        }
    }

我不確定,但從你的代碼來看,我只能認為

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

可能會阻止您的用戶界面。 我認為它執行您的DidBecomeActive方法,然后在延遲幾秒鍾后開始執行handleNotification 因此,如果可能,請使用performSelectorInBackground ,即如果您不在handleNotification:中進行任何與用戶界面相關的更改。

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

希望這可以幫助。

如果您需要更多幫助,請告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM