Post

Replies

Boosts

Views

Activity

SwiftUI intermittent Background and Launch crashes on iOS 15 TabView
Hi I'm hoping that somebody here can help me. We recently released an update to one of our apps in which added a TabView. The app is using SwiftUI with no launch view. Since this version was released there are a lot of crashes being reported through the app store and organiser. These seem to all be on iOS 15.x. We have users on both 14 and 15. When we have seen this ourselves it is crashing in the background(TestFlight dialog pops up on home screen saying app has crashed, send feedback) or immediately on launch. Opening it again after a crash everything seems fine and it behaves as normal. Looking through the Apple crash logs I can see that it's a SIGSEGV error trying to access an invalid address, so something is uninitialised. My suspicion is that there are some .environmentObject objects that are being injected from the App class which are somehow uninitialised in these crashes, but I can't see how to remedy this as they are all marked as @StateObject in the root App class and injected as environmentObjects. So to my understanding this is correct and the subviews should never exist without these having first been initialised. I also noticed that the Launch time is often long before the DateTime of the crash. Which is surprising since I know when its happened to me that I had not opened the app at all in that time, it does go some way to explaining the background crashes. I've included a crash log below if it helps in diagnosing. Sample crash log Thanks in advance
0
1
618
Jun ’22
UserDefaults not persisting data
Hi, We are experiencing what seems to be a fairly widespread, but intermittent issue with one of our apps. Anecdotally I have only seen this in person on iOS 14.4 devices, but I suspect based on our analytics that it is also happening on other versions too. Basically the UserDefaults seems to be reverting to its initial defaults setting for some users which is causing our pre installed flag to revert to nil. This flag is purely used as a "firstLaunch" detection to determine if the app should clear its cache and show the first time login flow. Therefore this property not saving is having the effect of logging a user out every time they close the app. I've attached the AppDelegate didFinishLaunching code below, only change is I have redacted our company name and replaced it with MyApp The important part which is intermittently failing is the if statement if !UserDefaults.standard.bool(forKey: "pre installed") || UserDefaults.standard.bool(forKey: "MyAppSettingsResetState") For clarity, once an app gets into this state it no longer seems to be able to save to the UserDefaults, so it will always log itself out on next launch. It also seems to fix itself if I delete the app from the phone and reinstall, then the UserDefaults return to working as expected.     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) - Bool {           SentrySDK.start { options in       options.dsn = Constants.sentryID       options.environment = Constants.sentryEnvName       options.debug = Constants.env == Env.Production ? false : true     }           _ = MyAppSDK.sharedSDK     MyAppSDK.sharedSDK.configure(baseURL: Constants.baseURL, gatewayBaseURL: Constants.gatewayBaseURL)     MyAppSDK.sharedSDK.errorLogging = SentryHelper()           AWSMobileClient.default().initialize { (userState, error) in       if let err = error {         print("error: \(err)")       }       if let userState = userState {         print("UserState: \(userState.rawValue)")       }     }           if !UserDefaults.standard.bool(forKey: "pre installed") || UserDefaults.standard.bool(forKey: "MyAppSettingsResetState") {       MyAppSDK.sharedSDK.logout()       MyAppSDK.sharedSDK.updateAPNToken(token: "")       UserDefaults.standard.set(true, forKey: "pre installed")       UserDefaults.standard.set(false, forKey: "MyAppSDKSettingsResetState")     }           UNUserNotificationCenter.current().getNotificationSettings { (settings) in       if settings.authorizationStatus == .authorized {         DispatchQueue.main.async {           UIApplication.shared.registerForRemoteNotifications()         }       }     }           UNUserNotificationCenter.current().delegate = self     settingsInfo()     return true   } If anyone has experienced this before and knows how to fix it or what might be causing some users apps to get into this state. I would love to hear from you, I've been going round in circles with this for several days now.
2
0
2.9k
Feb ’21