Fix SIGABRT crash from background-location Info.plist misconfiguration#4
Merged
Conversation
The app aborted on launch (SIGABRT) once 'Always' location authorization was granted. Root cause: LocationManager set `allowsBackgroundLocationUpdates = true`, but the built Info.plist was missing `UIBackgroundModes = location`. CoreLocation throws an exception when that setter runs without the background mode declared. Why the plist was missing it: the project uses GENERATE_INFOPLIST_FILE=YES and declared `INFOPLIST_KEY_UIBackgroundModes = location`, but UIBackgroundModes is NOT one of the INFOPLIST_KEY_* names Xcode synthesizes into the generated plist, so it was silently dropped (the usage strings, which ARE synthesized keys, made it through). This is pre-existing code from the background-location feature (#2) that had only been compile-verified, never run. Fix (two layers): - Add BuildConfig/Info.plist declaring UIBackgroundModes=[location] and point INFOPLIST_FILE at it in both Debug/Release. Kept outside the 'Party Watcher/' synchronized folder so it isn't also copied as a bundle resource (which would cause 'Multiple commands produce Info.plist'). GENERATE_INFOPLIST_FILE stays YES and merges this on top. - Harden enableBackgroundUpdatesIfPermitted(): only enable background updates if Bundle.main's UIBackgroundModes actually contains 'location', so any future plist regression degrades to foreground-only instead of crashing. Verified: built plist now contains UIBackgroundModes=[location] (usage strings retained); app launches and stays running in the Simulator with always-location granted (the exact condition that crashed before); no new crash reports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The crash
The app aborted on launch with SIGABRT once "Always" location authorization had been granted (e.g. after testing the location prompt once). Crash report pinpointed it:
Root cause
LocationManagersetsallowsBackgroundLocationUpdates = true, but the builtInfo.plistwas missingUIBackgroundModes = location. CoreLocation throws (→abort()) when that property is set without the background mode declared.Why it was missing: the project uses
GENERATE_INFOPLIST_FILE = YESand declaredINFOPLIST_KEY_UIBackgroundModes = location, butUIBackgroundModesis not one of theINFOPLIST_KEY_*names Xcode synthesizes into the generated plist — so it was silently dropped. (The location usage strings are synthesized keys, so those made it through, which is why the prompt appeared but the app then crashed.) This is pre-existing code from the background-location feature (#2) that had been compile-verified but never actually run.Fix (two layers)
BuildConfig/Info.plistdeclaringUIBackgroundModes=[location]and pointINFOPLIST_FILEat it (both Debug/Release).GENERATE_INFOPLIST_FILE=YESstays on and merges this file on top. It's kept outside theParty Watcher/synchronized source folder on purpose — a plist inside it gets auto-added to Copy Bundle Resources and used asINFOPLIST_FILE, which produces a "Multiple commands produce Info.plist" build error.enableBackgroundUpdatesIfPermitted()to only enable background updates ifBundle.main'sUIBackgroundModesactually contains"location". Any future plist regression now degrades to foreground-only tracking instead of aborting.Verification
xcodebuild build→ BUILD SUCCEEDED; builtInfo.plistnow containsUIBackgroundModes = [location](verified with PlistBuddy), usage strings retained.location-always(the exact condition that crashed before), launched → stays running, no new crash reports.Investigation
Root cause and fix were confirmed by three parallel read-only investigators (crash-report analysis, plist-synthesis research, and a broader crash-risk audit) before any code changed.