Post

Replies

Boosts

Views

Activity

Correct use of weak 'self' in nested escaping blocks
I would like someone's help to understand the correct use of weak self in nested escaping blocks. It would be great if someone could tell me whether what I'm doing below is correct. Thank you. import UIKit class MyClass {   var closingTimer: Timer?       func f1() {     /**      Some work here       */   }       func f2() {     closingTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval.init(5), repeats: true, block: { [weak self] (t: Timer) in       /**        Some work here         */               if let _ = self {         DispatchQueue.main.async { [weak self] in           self?.f1()         }       }     })           } }
1
0
1.9k
Oct ’22
How to keep a WebSocket connection created on a WKWebView open for some time after entering background
In my app I'm loading a website in a WKWebView. This website opens a WebSocket connection (CometD3). My problem is that the connection drops as soon as the app enters background. I am aware that Apple requires developers to request special capabilities to keep socket connections opened in the background. My app doesn't fit the description of an app that Apple may allow this. The requirement is not to keep it alive forever but to avoid reconnection when the user switches between apps or if they happen to be interrupted (e.g. phone call, text message). I'm look at about 30sec here. I have already tried https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/extending_your_app_s_background_execution_time but didn't work. Also, I did not have this problem with UIWebView.
0
0
1.3k
Jun ’21