Post

Replies

Boosts

Views

Activity

Reply to UserDefaults Issue After iPhone Restart
I use a set of general functions that get values from the defaults, and return a fallback value if the defaults couldn't be read. It's helpful to abstract this out so you can change the way you store such data in future and only need to change these functions, not everywhere you currently access defaults. func defaultsGetBool(forKey key: String, withFallback fallback: Bool) -> Bool { guard let value = UserDefaults(suiteName: kAppGroup)?.object(forKey: key) else { return fallback } return value as? Bool ?? fallback } func defaultsGetDate(forKey key: String, withFallback fallback: Date) -> Date { guard let value = UserDefaults(suiteName: kAppGroup)?.object(forKey: key) else { return fallback } return value as? Date ?? fallback } func defaultsGetInt(forKey key: String, withFallback fallback: Int) -> Int { guard let value = UserDefaults(suiteName: kAppGroup)?.object(forKey: key) else { return fallback } return value as? Int ?? fallback } func defaultsGetString(forKey key: String, withFallback fallback: String) -> String { guard let value = UserDefaults(suiteName: kAppGroup)?.object(forKey: key) else { return fallback } return value as? String ?? fallback } func defaultsSet(_ value: Any, forKey key: String) { UserDefaults(suiteName: kAppGroup)?.set(value, forKey: key) UserDefaults(suiteName: kAppGroup)?.synchronize() } And I use them like this: func defaultsGetSettingsEvents() -> Int { return defaultsGetInt(forKey: kSettingsEvents, withFallback: 10) } func defaultsUpdateSettingsEvents(_ value: Int) { defaultsSet(value as Int, forKey: kSettingsEvents) } So, when the app launches I get the events and ask for a fallback of 10 if it couldn't get that value. When I update that value, it's stored and defaults are synchronised. In your situation where the defaults aren't accessed correctly initially, this would appear as though the defaults have been reset - because you'd be returning fallback values. Are you sure you're accessing them in every place from your app group? Are you using Strings for the keys - perhaps there's a typo? Use constants instead: let kSettingsEvents: String = "settingsEvents".
Topic: App & System Services SubTopic: General Tags:
Apr ’24
Reply to VPN - Swift
It seems like you've done this the wrong way round. You should find out how to make a VPN, get it working as a bare bones app - no frills - then add a UI to it. Alternatively, you develop the UI as you go when you're getting the VPN to work. As for how to write a VPN, I think that's a bit out of scope for these forums. You might want to do a search on the internet and figure out how to do it.
Topic: App & System Services SubTopic: Core OS Tags:
Apr ’24
Reply to Unable to install MongoDB OpenGL on my MacBook Pro M1 system
I loathe posts like this because there's no information at all. What version of macOS are you using? What version of MongoDB OpenGL are you trying to install? Where did you get it from? What have you tried? Were there any errors? Have you tried asking the developers of MongoDB OpenGL rather than third-party developers who write apps for Apple's platforms (us)?
Topic: Graphics & Games SubTopic: General Tags:
Apr ’24
Reply to Using ios passcode in my app
Use LocalAuthentication. If your device doesn't have biometrics (Touch ID, Face ID) then you'll be asked for the iOS passcode. If you have biometrics that will be attempted first. If it fails, you're asked for the iOS passcode. Is there some reason you want to skip biometrics and go straight for the passcode? That would be annoying for users who expect to be able to unlock an app with biometrics.
Topic: Privacy & Security SubTopic: General Tags:
Apr ’24
Reply to Siri and iCloud
These are the Developer Forums, where THIRD-PARTY developers who are writing code for their apps for Apple's platforms get together to figure out code and fix issues. This is NOT the place where Apple's employees hang out and take suggestions from the public. You need to visit discussions.apple.com for your question. If you have a suggestion, raise it feedback.apple.com Thanks.
Topic: App & System Services SubTopic: Hardware Tags:
Apr ’24
Reply to OS 17.5 problems
What happens when you try to call an Android phone? Is it every Android phone? What about the texts? Do they fail to send? What happens? You can't simply tell us something isn't working without actually telling us what happens. How do you expect us to help you with so little information?
Topic: App & System Services SubTopic: Core OS Tags:
Apr ’24
Reply to Safari logs out all my accounts websites.
These are the Developer Forums, where third-party developers writing apps for Apple's platforms get together to chat about code and fix issues in their apps. This isn't where Apple's own developers (their employees) hang out. You need to ask this at discussions.apple.com Thanks.
Topic: Safari & Web SubTopic: General Tags:
Apr ’24