dispatch-queue

how to stop a dispatchQueue in swift

霸气de小男生 提交于 2020-08-05 01:54:33
问题 I have a DispatchQueue for a introViewController that shows a gif for 11 seconds and then display my login page... But also have a button that skip the intro and display the login. When I click it the time still running and when I am navigating in the app goes back to the login when the time ends. this is my class class GifClass: UIViewController { @IBOutlet weak var gifImage: UIImageView! @IBOutlet weak var skipButton: UIButton! override func viewDidLoad() { super.viewDidLoad() gifImage

Why a sync block of code always call on main thread?

人走茶凉 提交于 2020-07-08 12:43:22
问题 I did the simple test with DispatchQueue: DispatchQueue.global(qos: .background).sync { if Thread.isMainThread { print("Main thread") } } It printed out: Main thread Why does this code execute on the main thread? It should be performed on a background thread (it was added to a background queue), right? 回答1: Because it doesn't actually have to. You're blocking the main thread by using sync. iOS is choosing to just execute it on the main thread instead of bothering to switch to a background

iOS Swift Timer in not firing if the App is in the background

穿精又带淫゛_ 提交于 2020-07-08 03:44:43
问题 I am developing a Cocoapod library in which, i have to Call a function when timer fires. I am using that Cocoapod in an iOS App, Timer is not firing when App goes to background state private var timer : DispatchSourceTimer? = nil let queue = DispatchQueue(label: "sample.timer") timer = DispatchSource.makeTimerSource(queue : queue) timer?.setEventHandler { [weak self] in self?.sendData() } timer?.scheduleRepeating(deadline: .now(), interval: .seconds(5)) 回答1: The fact that you are using a GCD

iOS Swift Timer in not firing if the App is in the background

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-08 03:42:36
问题 I am developing a Cocoapod library in which, i have to Call a function when timer fires. I am using that Cocoapod in an iOS App, Timer is not firing when App goes to background state private var timer : DispatchSourceTimer? = nil let queue = DispatchQueue(label: "sample.timer") timer = DispatchSource.makeTimerSource(queue : queue) timer?.setEventHandler { [weak self] in self?.sendData() } timer?.scheduleRepeating(deadline: .now(), interval: .seconds(5)) 回答1: The fact that you are using a GCD

DispatchQueue : Cannot be called with asCopy = NO on non-main thread

不问归期 提交于 2020-06-24 10:58:28
问题 I am presenting the UIAlertController on the main thread as : class HelperMethodClass: NSObject { class func showAlertMessage(message:String, viewController: UIViewController) { let alertMessage = UIAlertController(title: "", message: message, preferredStyle: .alert) let cancelAction = UIAlertAction(title: "Ok", style: .cancel) alertMessage.addAction(cancelAction) DispatchQueue.main.async { viewController.present(alertMessage, animated: true, completion: nil) } } } And I am calling the method

Stop a DispatchQueue that is running on the main thread

孤人 提交于 2020-01-09 10:52:28
问题 I have this block of code: DispatchQueue.main.asyncAfter(deadline: .now() + (delay * Double(isDelayAccounted.hashValue)) + extraDelay) { self.isShootingOnHold = false self.shoot() self.shootingEngine = Timer.scheduledTimer(timeInterval: (Double(60)/Double(self.ratePerMinute)), target: self, selector: #selector(ShootingEnemy.shoot), userInfo: nil, repeats: true) } Now, I want to be able to stop this thread from executing. How can I stop it from being executed? For instance, after 3 seconds, I

Is DispatchQueue.global(qos: .userInteractive).async same as DispatchQueue.main.async

Deadly 提交于 2019-12-30 07:51:25
问题 I was going through the tutorial : https://www.raywenderlich.com/148513/grand-central-dispatch-tutorial-swift-3-part-1 And came across the definition of QoS class User-interactive . Its mentioned there that this should run on main thread. So, my question is then what is the difference between the DispatchQueue.global(qos: .userInteractive).async{} and DispatchQueue.main.async{} Thanks!! 回答1: The "quality of service" definitions are described here: https://developer.apple.com/library/content

AudioUnit callback and synchronization: how to ensure thread safety with GCD

强颜欢笑 提交于 2019-12-23 04:33:24
问题 I am building an audio app based on the AudioUnit callback facility and a graph of audio processing nodes. I know that the callback is executed in a separate (high priority?) thread and therefore all interaction with my processing nodes, such as e.g. changing EQ parameters while playing, should be done in a thread safe manner. In other words, the nodes should be protected from modification while the audio callback chain is being executed. The way I understand it in terms of more low-level

Is the following a safe use of dispatch_set_target_queue()?

℡╲_俬逩灬. 提交于 2019-12-16 18:07:08
问题 What I want to do is create an indirect queue targeting the main queue. dispatch_queue_t myQueue = dispatch_queue_create("com.mydomain.my-main-queue", NULL); dispatch_set_target_queue(myQueue, dispatch_get_main_queue()); My ultimate goal is to use the queue as the underlyingQueue property of an NSOperationQueue, because Apple's documentation clearly states not to use dispatch_get_main_queue(). Though using an indirect queue it technically is following the documentation. The reason for all

Firebase query not executing in the correct order?

非 Y 不嫁゛ 提交于 2019-12-13 08:59:42
问题 I fetch data and display in a tableView, the problem is the data is not executing in the correct order. I have tried: for case let child as DataSnapshot in data!.children.reversed() { let newDispatchGroup = DispatchGroup() let commentID = child.key let uid = child.childSnapshot(forPath: "UID").value as! String let commentText = child.childSnapshot(forPath: "Comment").value! let timeStamp = child.childSnapshot(forPath: "timeStamp").value! let date = ConvertDate(mediaTimestamp: timeStamp as!