I had the same problem. Couldn't get this to work in the Simulator or on an iPhone running the iOS 14 beta. The ScenePhase doc's sample code didn't work for me when adding it to an App or Scene.
Finally worked by adding it into the View instead (the first example in the ScenePhase doc). Seems more limited, but works.
struct ContentView: View {
@Environment(\.scenePhase) var scenePhase
var body: some View {
Text("Hello, world!").padding()
.onChange(of: scenePhase) { phase in
print("scenePhase change \(phase)")
}
}
}
Post
Replies
Boosts
Views
Activity
Have you tried @NSApplicationDelegateAdaptor?
I've only tested it briefly with applicationDidFinishLaunching(), but that method does get called.
@main
struct TestApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {}
}
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
print("hello")
}
}
Unfortunately, this isn't of any help. But I am seeing a very similar problem after updating to Big Sur. Xcode crashes immediately from Preferences when trying to access the Git subtab under Source Control, or when trying to add a GitHub account under Accounts. Very frustrating.
Try opening it in Xcode. Apps created in iPad Playgrounds4 (with a file extension *.swiftpm) can be opened in Xcode 13.2. But if you haven't already updated to Xcode 13.2, see the comments in the Xcode forum; there are some problems with the Mac App Store version.
Just in case anyone else makes the same mistake I did. When adding the Bundle Identifier under Signing & Capabilities, somehow I had added it to the iOS section, but not to the field directly under Team (maybe because I added the BundleID before changing the Team to me?). I noticed this after reading through this post and going back to check if I had everything correct. I saw that there were 2 Bundle Identifier fields and the top one still had the Apple sample project BundleID. When I copied my BundleID to the field underneath Team, everything started working (& the 2nd Bundle Identifier field in the iOS section just disappeared).
I think this requires adding @Bindable to the appData declaration.
@Bindable var appData:AppData
This is from WWDC23 "Discover Observation in Swift" 6:27
I'm not sure if the timing was just coincidental, but I had the same problem and after I quit & re-opened Xcode I was able to download the iOS Simulator.
I had the same problem (& tried the same cleaning/deleting steps) when I first installed Xcode 16 beta 2. It only occurred in a project that I had created using Xcode 16 beta 1. I never could figure out what was causing it. I ended up just re-creating the project fresh in beta 2 and that worked. Luckily it wasn't a very big project. I copied over most of the code files as-is from the crashing project, so I suspect Xcode was just "confused" about something in the project file.