@@ -22,11 +22,13 @@ struct ContentView: View {
2222 bgImage
2323 actionButtons
2424 }
25+ . background ( . black)
2526 . navigationTitle ( " SwiftPizza 🍕 " )
2627 . toolbar {
2728 ToolbarItemGroup ( placement: . navigationBarLeading) {
2829 Text ( " For Developers " )
2930 . bold ( )
31+ . foregroundColor ( . white)
3032 }
3133 ToolbarItemGroup ( placement: . navigationBarTrailing) {
3234 Button ( action: { startPizzaAd ( ) } ) {
@@ -38,7 +40,6 @@ struct ContentView: View {
3840 . tint ( . red)
3941 }
4042 }
41- . preferredColorScheme ( . dark)
4243 . onOpenURL ( perform: { url in
4344 // MARK: Handle Widgets
4445 driver = url. absoluteString. replacingOccurrences ( of: " pizza:// " , with: " " )
@@ -64,53 +65,58 @@ struct ContentView: View {
6465 image. resizable ( ) . scaledToFill ( )
6566 } placeholder: {
6667 ProgressView ( )
67- } . ignoresSafeArea ( . all)
68+ } . frame ( width: UIScreen . main. bounds. size. width)
69+ . ignoresSafeArea ( . all)
6870 }
6971 var actionButtons : some View {
70- VStack ( spacing : 0 ) {
72+ VStack {
7173 Spacer ( )
72-
73- Button ( action: { showAllDeliveries ( ) } ) {
74- HStack {
75- Spacer ( )
76- Text ( " Show All Orders 🍕 " ) . font ( . headline)
77- Spacer ( )
78- } . frame ( height: 50 )
79- } . tint ( . brown)
80-
81- HStack ( spacing: 0 ) {
82- Button ( action: { startDeliveryPizza ( ) } ) {
74+ VStack ( spacing: 0 ) {
75+ Button ( action: { showAllDeliveries ( ) } ) {
8376 HStack {
8477 Spacer ( )
85- Text ( " Start Ordering 👨🏻🍳 " ) . font ( . headline)
78+ Text ( " Show All Orders 🍕 " ) . font ( . headline)
8679 Spacer ( )
87- } . frame ( height: 50 )
88- } . tint ( . blue)
89- Button ( action: { updateDeliveryPizza ( ) } ) {
80+ } . frame ( height: 45 )
81+ } . tint ( . brown)
82+
83+ HStack ( spacing: 0 ) {
84+ Button ( action: { startDeliveryPizza ( ) } ) {
85+ HStack {
86+ Spacer ( )
87+ Text ( " Start Ordering 👨🏻🍳 " ) . font ( . headline)
88+ Spacer ( )
89+ } . frame ( height: 45 )
90+ } . tint ( . blue)
91+ Button ( action: { updateDeliveryPizza ( ) } ) {
92+ HStack {
93+ Spacer ( )
94+ Text ( " Update Order 🫠 " ) . font ( . headline)
95+ Spacer ( )
96+ } . frame ( height: 45 )
97+ } . tint ( . purple)
98+ }
99+
100+ Button ( action: { stopDeliveryPizza ( ) } ) {
90101 HStack {
91102 Spacer ( )
92- Text ( " Update Order 🫠 " ) . font ( . headline)
103+ Text ( " Cancel Order 😞 " ) . font ( . headline)
93104 Spacer ( )
94- } . frame ( height: 50 )
95- } . tint ( . purple)
96- } . frame ( maxWidth: UIScreen . main. bounds. size. width)
97-
98- Button ( action: { stopDeliveryPizza ( ) } ) {
99- HStack {
100- Spacer ( )
101- Text ( " Cancel Order 😞 " ) . font ( . headline)
102- Spacer ( )
103- } . frame ( height: 50 )
104- . padding ( . bottom)
105- } . tint ( . pink)
105+ } . frame ( height: 45 )
106+ } . tint ( . pink)
107+ }
108+ . buttonStyle ( . bordered)
109+ . buttonBorderShape ( . roundedRectangle( radius: 0 ) )
110+ . background ( . thickMaterial)
111+ . cornerRadius ( 25 )
112+ . padding ( . horizontal, 5 )
106113 }
107- . buttonStyle ( . borderedProminent)
108- . buttonBorderShape ( . roundedRectangle( radius: 0 ) )
109- . ignoresSafeArea ( edges: . bottom)
110114 }
111115
112116 // MARK: - Functions
113117 func startDeliveryPizza( ) {
118+ print ( ActivityAuthorizationInfo ( ) . areActivitiesEnabled)
119+
114120 let pizzaDeliveryAttributes = PizzaDeliveryAttributes ( numberOfPizzas: 1 , totalAmount: " $99 " )
115121
116122 let initialContentState = PizzaDeliveryAttributes . PizzaDeliveryStatus ( driverName: " TIM 👨🏻🍳 " , estimatedDeliveryTime: Date ( ) ... Date ( ) . addingTimeInterval ( 15 * 60 ) )
@@ -119,15 +125,24 @@ struct ContentView: View {
119125 let deliveryActivity = try Activity< PizzaDeliveryAttributes> . request(
120126 attributes: pizzaDeliveryAttributes,
121127 contentState: initialContentState,
122- pushType: nil )
128+ pushType: . token ) // Enable Push Notification Capability First (from pushType: nil)
123129
124130 print ( " Requested a pizza delivery Live Activity \( deliveryActivity. id) " )
125-
126- showAlert = true
127- alertMsg = " Requested a pizza delivery Live Activity \( deliveryActivity. id) "
128-
131+
132+ // Send the push token to server
133+ Task {
134+ for await pushToken in deliveryActivity. pushTokenUpdates {
135+ let pushTokenString = pushToken. reduce ( " " ) { $0 + String( format: " %02x " , $1) }
136+ print ( pushTokenString)
137+
138+ alertMsg = " Requested a pizza delivery Live Activity \( deliveryActivity. id) \n \n Push Token: \( pushTokenString) "
139+ showAlert = true
140+ }
141+ }
129142 } catch ( let error) {
130143 print ( " Error requesting pizza delivery Live Activity \( error. localizedDescription) " )
144+ alertMsg = " Error requesting pizza delivery Live Activity \( error. localizedDescription) "
145+ showAlert = true
131146 }
132147 }
133148 func updateDeliveryPizza( ) {
@@ -195,10 +210,14 @@ struct ContentView: View {
195210 let deliveryActivity = try Activity< PizzaAdAttributes> . request(
196211 attributes: pizzaAdAttributes,
197212 contentState: initialContentState,
198- pushType: nil )
213+ pushType: . token ) // Enable Push Notification Capability First (from pushType: nil)
199214 print ( " Requested a pizza ad Live Activity \( deliveryActivity. id) " )
215+ alertMsg = " Requested a pizza ad Live Activity \( deliveryActivity. id) "
216+ showAlert = true
200217 } catch ( let error) {
201218 print ( " Error requesting pizza ad Live Activity \( error. localizedDescription) " )
219+ alertMsg = " Error requesting pizza ad Live Activity \( error. localizedDescription) "
220+ showAlert = true
202221 }
203222 }
204223
0 commit comments