Post

Replies

Boosts

Views

Activity

Reply to Unexpected order of scene delegate method calls in Swift iOS app
So the main question is why it creates the 2nd scene if you close the app quickly when there are other apps are in the minimized (background) state. Maybe it's to take a snapshot of the app. But it seems weird why the system doesn't do so if there is no other apps minimized. Also, it can lead to unexpected behavior if you have something that is triggered by sceneWillEnterForeground in your app. For instance if you fetch some data from backend, the request will be triggered but no response will be received. In my case, if access token is expired, it lead to my app making a refresh token request, making the backend generate a new access and refresh tokens. The problem is before the response from backend is received, the app is terminated, and the tokens are not stored in the app. On the next launch, the app uses an old already invalid refresh token, receives 401 "Refresh token is not assigned to the user" response and the user gets logged out. If using AppDelegate instead of SceneDelegate and quickly terminating the app, I get the following events: 11:42:33.615 applicationDidEnterBackground <UIApplication: 0x10930bc20> 11:42:33.965 applicationWillEnterForeground <UIApplication: 0x10930bc20> 11:42:33.988 applicationDidEnterBackground <UIApplication: 0x10930bc20> I'm using RxSwift and AppDelegate in my app, so I've fixed it by combining applicationDidBecomeActive and applicationDidEnterBackground, and adding a distinctUntilChanged and a 1 second throttle to the events. This approach allows me to accurately determine whether the app is in the foreground, while disregarding the extraneous applicationWillEnterForeground event.
Jun ’23
Reply to Apple Watch cannot reconnect
The problem was that my MacBook was connected to the 5 GHz WI-FI network while Apple Watch was connected to the same network but to 2.4 GHz. Changing MacBook's WI-FI to the SAME network but 2.4 GHz helped. I'm using Apple Watch Series 4 with WatchOS 10.3.1 and Xcode 15.3 (15E5202a) Release Candidate. It looks like the paired iPhone's network can be kept as 5 GHz, but you can try changing it too if the previous step doesn't help.
Mar ’24