Skip to content

Commit 66ed744

Browse files
committed
Fix bugs
1 parent c995012 commit 66ed744

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

WidgetDemo/WidgetDemo.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Widgets: WidgetBundle {
2020
struct PizzaDeliveryActivityWidget: Widget {
2121
var body: some WidgetConfiguration {
2222
ActivityConfiguration(for: PizzaDeliveryAttributes.self) { context in
23-
// For devices that don't support the Dynamic Island.
23+
// MARK: - For devices that don't support the Dynamic Island.
2424
VStack(alignment: .leading) {
2525
HStack {
2626
VStack(alignment: .leading) {
@@ -69,10 +69,11 @@ struct PizzaDeliveryActivityWidget: Widget {
6969
.foregroundColor(.secondary)
7070
.padding(.horizontal, 5)
7171
}.padding(15)
72+
// MARK: - For Dynamic Island
7273
} dynamicIsland: { context in
7374
DynamicIsland {
7475
DynamicIslandExpandedRegion(.leading) {
75-
Label("\(context.attributes.numberOfPizzas) Pizzas", systemImage: "bag")
76+
Label("\(context.attributes.numberOfPizzas) Pizza", systemImage: "bag")
7677
.font(.title2)
7778
}
7879
DynamicIslandExpandedRegion(.trailing) {
@@ -96,7 +97,7 @@ struct PizzaDeliveryActivityWidget: Widget {
9697
DynamicIslandExpandedRegion(.bottom) {
9798
// Deep Linking
9899
HStack {
99-
Link(destination: URL(string: "pizza://TIM")!) {
100+
Link(destination: URL(string: "pizza://contact:TIM")!) {
100101
Label("Contact driver", systemImage: "phone.circle.fill")
101102
.font(.caption)
102103
.padding()
@@ -109,11 +110,11 @@ struct PizzaDeliveryActivityWidget: Widget {
109110
.padding()
110111
}.background(Color.red)
111112
.clipShape(RoundedRectangle(cornerRadius: 15))
112-
}.padding()
113+
}
113114
}
114115
} compactLeading: {
115116
Label {
116-
Text("\(context.attributes.numberOfPizzas) Pizzas")
117+
Text("\(context.attributes.numberOfPizzas) Pizza")
117118
} icon: {
118119
Image(systemName: "bag")
119120
}

iOS16-Live-Activities/ContentView.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ActivityKit
1010

1111
struct ContentView: View {
1212

13-
@State var showDeepLinkAction: Bool = false
13+
@State var showContactAction: Bool = false
1414
@State var driver: String = ""
1515
@State var showAlert: Bool = false
1616
@State var alertMsg: String = ""
@@ -41,15 +41,19 @@ struct ContentView: View {
4141
}
4242
}
4343
.onOpenURL(perform: { url in
44-
// MARK: Handle Widgets
45-
driver = url.absoluteString.replacingOccurrences(of: "pizza://", with: "")
46-
showDeepLinkAction = true
44+
withAnimation {
45+
if url.absoluteString.contains("contact") {
46+
driver = url.absoluteString.replacingOccurrences(of: "pizza://contact:", with: "")
47+
showContactAction = true
48+
} else if url.absoluteString.contains("cancelOrder") {
49+
stopDeliveryPizza()
50+
}
51+
}
4752
})
48-
.confirmationDialog("Call Driver", isPresented: $showDeepLinkAction)
49-
{
53+
.confirmationDialog("Call Driver", isPresented: $showContactAction) {
5054
Link("(800)442–4000", destination: URL(string: "tel:8004424000")!)
5155
Button("Cancel", role: .cancel) {
52-
showDeepLinkAction = false
56+
showContactAction = false
5357
}
5458
} message: {
5559
Text("Are you sure to call \(driver)?")

0 commit comments

Comments
 (0)