Hi im new to swift and I to want run a function in the background, my problem is that once the function is running the hole app freezes I can't use the interface until the function end.
StartStream
is a button that will call the function self.StreamCam
for streaming the camera and then it will move the current view to CAMView
to see the camera interface.
here's what I used to call the the function :
@IBAction func StartStream(sender: UIButton) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("CAMView") as! CAM
let seconds = 2.0
let delay = seconds * Double(NSEC_PER_SEC)
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
self.StreamCam(self.session)
})
dispatch_async(dispatch_get_main_queue(), {
self.presentViewController(nextViewController, animated:true, completion:nil)});
});
}
Any suggestions?