I have a Siri Intent that displays a simple UI. When the user taps on it, the app is launched.
When the app is in the background, I use the following code
in the Scene Delegate to capture what the user did and take the user to the right view. It works as expected.
				func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
						print("CONTINUE USER ACTIVITY")
						guard let intent = userActivity.interaction?.intent as? WasteWizardIntent else {
								print("AppDelegate: WasteWizardIntent - FALSE")
								//return false
								return
						}
						print("AppDelegate: WasteWizardIntent - TRUE")
						print(intent)
						appState.selectedTab = .wastewizard
						appState.deepLinkActionSheet = true
						appState.deepLinkString = intent.garbage!
						//contentView.wasteWizard.viewModel.goToWasteItem(for: intent.garbage!)
				}
However, I can't figure out what to do when the app is launched when it is NOT in the background.
My understanding is that UIScene.ConnectionOptions should be populated, but it's empty.
In the SceneDelegate scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
method. When I put a breakpoint, the userActvity, intent and handoffUserActivityType are all nil.
								let window = UIWindow(windowScene: windowScene)
								window.rootViewController = UIHostingController(rootView: contentView)
								RootAlerter.shared.rootViewController = window.rootViewController
								self.window = window
								window.makeKeyAndVisible()
								let userActivity = connectionOptions.userActivities
								let string = connectionOptions.handoffUserActivityType
								let intent = userActivity?.interaction?.intent as? WasteWizardIntent
								print("handoff type \(connectionOptions.handoffUserActivityType)")
				}
I also tried the following methods but they never get called:
				func scene(_ scene: UIScene, didUpdate userActivity: NSUserActivity)
				func scene(_ scene: UIScene, willContinueUserActivityWithType userActivityType: String)
Also tried this in the AppDelegate:
Post
Replies
Boosts
Views
Activity
I'm using a 100% SwiftUI app, currently on Xcode 12 Beta 4
In my ContentView, I have a simple TabView
struct ContentView: View {
		var body: some View {
TabView {
AgendaView()
.tabItem {
Image(systemName: "list.bullet")
Text("Agenda")
}
HealthView()
.tabItem {
Image(systemName: "heart")
Text("Health")
}
}
		}
}
The AgendaView and HealthView have onAppear methods. On App launch, the AgendaView is the one visible, but onAppear is called for both AgendaView and HealthView.
Why is that? Shouldn't onAppear be called only when the view actually appears on screen?
Code for HealthView and AgendaView
struct AgendaView: View {
		var body: some View {
VStack {
Text("Hello, AgendaView!")
}.onAppear{
print("AgendaView.onAppear")
}.onDisappear(){
print("AgendaView.onDisappear")
}
		}
}
struct HealthView: View {
		var body: some View {
VStack {
Text("Hello, HealthView!")
}.onAppear{
print("HealthView.onAppear")
}.onDisappear(){
print("HealthView.onDisappear")
}
		}
}
I have multiple widgets in my application, and they all appear as the "placeholder" view.
In my snapshot code (shown below), the information is returned in less than a second. I even tried using sample data rather than retrieving the data from HealthKit (the commented out code).
In fact, you can briefly see the data show up in Widget Gallery in a video I took, before it switches to the placeholder view. (For some reason the forums aren't allowing me to link to the video)
Any idea what's going on?
public func snapshot(for configuration: HealthStatTypeSelectionIntent, in context: Context, completion: @escaping (HealthEntry) -> ()) {
print("HealthWidget.snapshot ")
let entry = HealthEntry(date: Date(), stat: HealthStat(type: .steps) )
completion(entry)
// HealthKitHelper.shared.getStats(for: .steps) { stat in
// let entry = HealthEntry(date: Date(), stat: stat )
// completion(entry)
//
// }
}
I'm having issues with EventKit.
Before requesting any data from EventKit, I request auth access to reminders and calendar.
In the App Sandbox configuration, I've checked off Reminders.
After requesting access, I call reset() on the EKEventStore I created.
The first time after access is approved, a call to "store.calendars(for: .event)" returns zero results (calls to "store.predicateForEvents" WILL return results).
If I force quit the app and launch it again, I get results for "store.calendars(for: .event)"
What am I missing here?
What's weird is, before all this started happening, everything was working correctly without the store.reset() call - even the calendars were getting returned.
However, I accidentally deleted my App's Target and had to recreate it. Since recreating the build target, I was NOT getting results for "store.predicateForEvents" until I called "store.reset()" after authorization was granted. But I still can't get the calendar list after first launch.
WeatherKit seems to work fine when I deploy a debug build on a real device, but whenever I try to deploy on a simulator, I get the following errors:
2022-09-13 17:51:56.118325-0400 Widget Wizard[63356:284415] [AuthService] Failed to generate jwt token for: com.apple.weatherkit.authservice with error: Error Domain=AMSErrorDomain Code=12 "Mescal Failed" UserInfo={NSLocalizedDescription=Mescal Failed, NSLocalizedFailureReason=SAPInit failed: -42049}
2022-09-13 17:51:56.119297-0400 Widget Wizard[63356:284415] [WeatherService] Encountered an error when fetching weather data subset; location=<+43.65320000,-79.38320000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 9/13/22, 5:51:55 PM Eastern Daylight Time, error=Error Domain=AMSErrorDomain Code=12 "Mescal Failed" UserInfo={NSLocalizedDescription=Mescal Failed, NSLocalizedFailureReason=SAPInit failed: -42049}
WeatherKitProvider.getWeather error Optional(<+43.65320000,-79.38320000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 9/13/22, 5:51:55 PM Eastern Daylight Time)
Mescal Failed
I have confirmed that everything is configured correctly in terms of certificates and profiles. It just doesn't work on any simulator. It seems a number of people on Twitter are having the same issues.