Skip to content

Commit c995012

Browse files
committed
Testing Remote Update
1 parent ba3eb90 commit c995012

File tree

7 files changed

+91
-44
lines changed

7 files changed

+91
-44
lines changed

WidgetDemo/WidgetDemo.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ struct PizzaDeliveryActivityWidget: Widget {
9797
// Deep Linking
9898
HStack {
9999
Link(destination: URL(string: "pizza://TIM")!) {
100-
Label("Contact driver", systemImage: "phone.circle.fill").padding()
100+
Label("Contact driver", systemImage: "phone.circle.fill")
101+
.font(.caption)
102+
.padding()
101103
}.background(Color.accentColor)
102104
.clipShape(RoundedRectangle(cornerRadius: 15))
103105
Spacer()
104106
Link(destination: URL(string: "pizza://cancelOrder")!) {
105-
Label("Cancel Order", systemImage: "xmark.circle.fill").padding()
107+
Label("Cancel Order", systemImage: "xmark.circle.fill")
108+
.font(.caption)
109+
.padding()
106110
}.background(Color.red)
107111
.clipShape(RoundedRectangle(cornerRadius: 15))
108112
}.padding()

WidgetDemoExtension.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>aps-environment</key>
6+
<string>development</string>
57
<key>com.apple.security.application-groups</key>
68
<array>
79
<string>group.io.startway.iOS16-Live-Activities</string>

iOS16-Live-Activities.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
321321
GCC_WARN_UNUSED_FUNCTION = YES;
322322
GCC_WARN_UNUSED_VARIABLE = YES;
323-
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
323+
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
324324
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
325325
MTL_FAST_MATH = YES;
326326
ONLY_ACTIVE_ARCH = YES;
@@ -374,7 +374,7 @@
374374
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
375375
GCC_WARN_UNUSED_FUNCTION = YES;
376376
GCC_WARN_UNUSED_VARIABLE = YES;
377-
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
377+
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
378378
MTL_ENABLE_DEBUG_INFO = NO;
379379
MTL_FAST_MATH = YES;
380380
SDKROOT = iphoneos;
@@ -399,6 +399,7 @@
399399
GENERATE_INFOPLIST_FILE = YES;
400400
INFOPLIST_FILE = "iOS16-Live-Activities/Info.plist";
401401
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
402+
INFOPLIST_KEY_NSSupportsLiveActivities = YES;
402403
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
403404
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
404405
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
@@ -432,6 +433,7 @@
432433
GENERATE_INFOPLIST_FILE = YES;
433434
INFOPLIST_FILE = "iOS16-Live-Activities/Info.plist";
434435
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
436+
INFOPLIST_KEY_NSSupportsLiveActivities = YES;
435437
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
436438
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
437439
INFOPLIST_KEY_UILaunchScreen_Generation = YES;

iOS16-Live-Activities/ContentView.swift

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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\nPush 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

iOS16-Live-Activities/Info.plist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@
1717
</array>
1818
<key>NSSupportsLiveActivities</key>
1919
<true/>
20+
<key>NSSupportsLiveActivitiesFrequentUpdates</key>
21+
<true/>
22+
<key>UIBackgroundModes</key>
23+
<array>
24+
<string>fetch</string>
25+
<string>remote-notification</string>
26+
</array>
2027
</dict>
2128
</plist>

iOS16-Live-Activities/iOS16-Live-Activities.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>aps-environment</key>
6+
<string>development</string>
57
<key>com.apple.security.application-groups</key>
68
<array>
79
<string>group.io.startway.iOS16-Live-Activities</string>

iOS16-Live-Activities/iOS16_Live_ActivitiesApp.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ import SwiftUI
99

1010
@main
1111
struct iOS16_Live_ActivitiesApp: App {
12+
init() {
13+
// Set toolbar and navigation title text color white
14+
let coloredAppearance = UINavigationBarAppearance()
15+
coloredAppearance.configureWithOpaqueBackground()
16+
coloredAppearance.backgroundColor = .clear
17+
coloredAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
18+
coloredAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
19+
coloredAppearance.shadowColor = .clear
20+
UINavigationBar.appearance().standardAppearance = coloredAppearance
21+
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
22+
}
1223
var body: some Scene {
1324
WindowGroup {
1425
ContentView()

0 commit comments

Comments
 (0)