Post

Replies

Boosts

Views

Created

How to work with user location in iOS 16 App Intents?
I'm working on an App Shortcut using the new AppIntents framework in iOS 16 and I'm trying to get the user's current location, everything is enabled and set-up correctly with the permissions func perform() async throws -> some IntentResult { //Request User Location IntentHelper.sharedInstance.getUserLocation() guard let userCoords = IntentHelper.sharedInstance.currentUserCoords else { throw IntentErrors.locationProblem } //How to wait for location?? return .result(dialog: "Worked! Current coords are \(userCoords)") { IntentSuccesView() } } And here is the IntentHelper class class IntentHelper: NSObject { static let sharedInstance = IntentHelper() var currentUserCoords: CLLocationCoordinate2D? private override init() {} func getUserLocation() { DispatchQueue.main.async { let locationManager = CLLocationManager() locationManager.delegate = self print("FINALLY THIS IS IT") self.currentUserCoords = locationManager.location?.coordinate print(self.currentUserCoords) } } } extension IntentHelper: CLLocationManagerDelegate { func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print(error) manager.stopUpdatingLocation() } } Problem is, this sometimes, very rarely works, most of the times it prints nil, so how would you go about waiting for the location?
0
0
772
Nov ’22
Images not rendering in new iOS 16 Widgets?
I'm working on a new .accessoryInline widget, introduces with iOS 16. It's very simple, only displays static text and an image, said image is a custom SF Symbol, validated and also used in other places in which it works just fine (for example a .accessoryRectangular widget). Here is my code: case .accessoryInline: HStack { Image("mysymbol.car") .resizable() .widgetAccentable() Text("My Static Title") } This however only renders the text when running the app and leaves a weird small space where the image should be. Am I doing something wrong or is it a bug?
1
0
1.5k
Oct ’22