I am new to SwiftUI development so I did the official SwiftUI-Landmark tutorial. The chapter Creating a watchOS App says that you should check the checkbox "Include Notification Scene" in the template when adding the WatchOSApp target. However, in my Xcode V 14.2 there is no such checkbox. Am I doing something wrong? Is there a possibility to add this scene afterwards?
This are the options i can choose:
I also posted this Question in the Apple Developer Forum. But till now nobody answered.
2
Answers
Only if you want to customize that scene. Otherwise watchOS will just display your notifications in a default interface.
When you create a project, you will see a generic ContentView file with your first view and a file named after your app that displays ContentView in a window in a scene.
You can just create a new scene and window for notifications here and customize the view in a separate file (to stay organized) just like for your application.
The checkbox is in fact missing in Xcode 14+ (as of Jan 2023). In Xcode 13 it creates additional files when you selected the checkbox, these files are:
NotificationView.swift
,NotificationController.swift
,ComplicationController.swift
,PushNotificationPayload.apns
, as well as two schemes to launch the notification and the complication.Fortunately, you don’t need complications to complete the tutorial, so you have only to create 3 files and one scheme before moving on to the Section 5 —
Create a Custom Notification Interface.
I provided the detailed explanation with screenshots in the blog post, but here is a short description of what you have to do:
Step 1: Create a NotificationView.swift
Create a new SwiftUI View file in the WatchLandmarks Watch App folder. Name it
NotificationView.swift
:Do not be confused about its stub content. The file will be modified during the next section of the Apple tutorial. For now you just need these files in a state they were created in Xcode 13.
Step 2: Create a NotificationController.swift
Create a Swift file called
NotificationController.swift
in the same folder:Step 3: Create a PushNotificationPayload.apns
In the same folder, create an Empty file (bottom of the new file screen) and call it
PushNotificationPayload.apns
. Paste its contents:Step 4: Create a Notification scheme
Now you need to create a scheme to run a notification with a custom view you just created.
(Notification)
to the scheme name for the sake of clarity. Click OK.From this state, you can easily continue with the tutorial.