Hello,
When attempting to assign the UNNotificationResponse to a Published property on the main thread inside UNUserNotificationCenterDelegate's method
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async
both Task { @MainActor in } and await MainActor.run are throwing a NSInternalInconsistencyException: 'Call must be made on main thread'.
I thought both of them were essentially doing the same thing, i.e. call their closure on the main thread. So why is this exception thrown? Is my understanding of the MainActor still incorrect, or is this a bug?
Thank you
Note: Task { await MainActor.run { ... } } and DispatchQueue.main.async don't throw any exception.
Post
Replies
Boosts
Views
Activity
Hello,
I would like to store CLAuthorizationStatus in the User Defaults using the AppStorage property wrapper, so that I can access it throughout the app as a simple variable rather than accessing the authorisation status every time via CLLocationManager which requires to import MapKit.
The problem is that this Enum rawValue Type is an Int32 (instead of Int, e.g. UNAuthorizationStatus), so the following does not work:
@AppStorage("locationSettings") var locationSettings: CLAuthorizationStatus = CLAuthorizationStatus.notDetermined
throws: Candidate requires that the types 'CLAuthorizationStatus.RawValue' (aka 'Int32') and 'Int' be equivalent (requirement specified as 'Value.RawValue' == 'Int') (SwiftUI.AppStorage)
I tried extending AppStorage to include an initializer with a RawRepresentable that has Int32 as rawValue but I can't find what to include in it to make it work.
extension AppStorage {
init(wrappedValue: Value, _ key: String, store: UserDefaults? = nil) where Value : RawRepresentable, Value.RawValue == Int32 {
}
}
Thanks in advance.