Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertController Showing With Delay

I am having a lot of delay with my UIAlert, whenever it loads I have to wait before I can click and then again for it to fully disappear. I have looked at other answers that recommended using dispatch_async(dispatch_get_main_queue(), {}). I have tried using this but to no avail. The alert pops up during the render loop for a scene kit game I am making (the scene is just a cube and when I pause the scene it is still delayed). Shouldn't rendering be done in the render thread anyway. I looked the through the time profile log to see if something was blocking the Main Thread but I did not see anything that caught my attention (I fairly new to the instruments).picture of call tree

Here is my code where I am creating the alert:

func share(){
    print("share funciton")
    let alert = UIAlertController(title: "Share", message: "Where do you want to share?", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "Twitter", style: .Default, handler: {(alert: UIAlertAction!) in
        print("twitter")
        
        self.showTwitter()
    }))
    self.presentViewController(alert, animated: false, completion: nil)
}

private func showTwitter() {
    if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter) {
        
        let tweetShare:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
        
        self.presentViewController(tweetShare, animated: true, completion: nil)
        
    } else {
        
        let alert = UIAlertController(title: "Accounts", message: "Please login to a Twitter account to tweet.", preferredStyle: UIAlertControllerStyle.Alert)
        
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
        
        self.presentViewController(alert, animated: true, completion: nil)
    }
}

Then I call share() when in the render loop with a dispatch_asych. I've been working at this bug for three days but have no idea what's causing the delay.

like image 334
egg Avatar asked Mar 31 '26 11:03

egg


1 Answers

Try turning slow animations off. Open simulator -> debug -> slow animations

like image 174
Maxwelll Avatar answered Apr 03 '26 17:04

Maxwelll