@@ -157,13 +157,18 @@ private extension SignalManager {
157157 #if os(watchOS) || os(macOS)
158158 self . signalCache. backupCache ( )
159159 #else
160- // run backup in background task to avoid blocking main thread while ensuring app stays open during write
161- let backgroundTaskID = UIApplication . shared. beginBackgroundTask ( )
162- DispatchQueue . global ( qos: . background) . async {
160+ if Bundle . main. bundlePath. hasSuffix ( " .appex " ) {
161+ // we're in an app extension, where `UIApplication.shared` is not available
163162 self . signalCache. backupCache ( )
163+ } else {
164+ // run backup in background task to avoid blocking main thread while ensuring app stays open during write
165+ let backgroundTaskID = UIApplication . shared. beginBackgroundTask ( )
166+ DispatchQueue . global ( qos: . background) . async {
167+ self . signalCache. backupCache ( )
164168
165- DispatchQueue . main. async {
166- UIApplication . shared. endBackgroundTask ( backgroundTaskID)
169+ DispatchQueue . main. async {
170+ UIApplication . shared. endBackgroundTask ( backgroundTaskID)
171+ }
167172 }
168173 }
169174 #endif
@@ -195,13 +200,18 @@ private extension SignalManager {
195200 #if os(watchOS) || os(macOS)
196201 self . signalCache. backupCache ( )
197202 #else
198- // run backup in background task to avoid blocking main thread while ensuring app stays open during write
199- let backgroundTaskID = UIApplication . shared. beginBackgroundTask ( )
200- DispatchQueue . global ( qos: . background) . async {
203+ if Bundle . main. bundlePath. hasSuffix ( " .appex " ) {
204+ // we're in an app extension, where `UIApplication.shared` is not available
201205 self . signalCache. backupCache ( )
206+ } else {
207+ // run backup in background task to avoid blocking main thread while ensuring app stays open during write
208+ let backgroundTaskID = UIApplication . shared. beginBackgroundTask ( )
209+ DispatchQueue . global ( qos: . background) . async {
210+ self . signalCache. backupCache ( )
202211
203- DispatchQueue . main. async {
204- UIApplication . shared. endBackgroundTask ( backgroundTaskID)
212+ DispatchQueue . main. async {
213+ UIApplication . shared. endBackgroundTask ( backgroundTaskID)
214+ }
205215 }
206216 }
207217 #endif
0 commit comments