Skip to content

Commit

Permalink
Testing Remote Update
Browse files Browse the repository at this point in the history
  • Loading branch information
1998code committed Jun 15, 2023
1 parent ba3eb90 commit c995012
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 44 deletions.
8 changes: 6 additions & 2 deletions WidgetDemo/WidgetDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ struct PizzaDeliveryActivityWidget: Widget {
// Deep Linking
HStack {
Link(destination: URL(string: "pizza://TIM")!) {
Label("Contact driver", systemImage: "phone.circle.fill").padding()
Label("Contact driver", systemImage: "phone.circle.fill")
.font(.caption)
.padding()
}.background(Color.accentColor)
.clipShape(RoundedRectangle(cornerRadius: 15))
Spacer()
Link(destination: URL(string: "pizza://cancelOrder")!) {
Label("Cancel Order", systemImage: "xmark.circle.fill").padding()
Label("Cancel Order", systemImage: "xmark.circle.fill")
.font(.caption)
.padding()
}.background(Color.red)
.clipShape(RoundedRectangle(cornerRadius: 15))
}.padding()
Expand Down
2 changes: 2 additions & 0 deletions WidgetDemoExtension.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.io.startway.iOS16-Live-Activities</string>
Expand Down
6 changes: 4 additions & 2 deletions iOS16-Live-Activities.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -374,7 +374,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -399,6 +399,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "iOS16-Live-Activities/Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSSupportsLiveActivities = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down Expand Up @@ -432,6 +433,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "iOS16-Live-Activities/Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSSupportsLiveActivities = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down
99 changes: 59 additions & 40 deletions iOS16-Live-Activities/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ struct ContentView: View {
bgImage
actionButtons
}
.background(.black)
.navigationTitle("SwiftPizza 🍕")
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
Text("For  Developers")
.bold()
.foregroundColor(.white)
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
Button(action: { startPizzaAd() }) {
Expand All @@ -38,7 +40,6 @@ struct ContentView: View {
.tint(.red)
}
}
.preferredColorScheme(.dark)
.onOpenURL(perform: { url in
// MARK: Handle Widgets
driver = url.absoluteString.replacingOccurrences(of: "pizza://", with: "")
Expand All @@ -64,53 +65,58 @@ struct ContentView: View {
image.resizable().scaledToFill()
} placeholder: {
ProgressView()
}.ignoresSafeArea(.all)
}.frame(width: UIScreen.main.bounds.size.width)
.ignoresSafeArea(.all)
}
var actionButtons: some View {
VStack(spacing:0) {
VStack {
Spacer()

Button(action: { showAllDeliveries() }) {
HStack {
Spacer()
Text("Show All Orders 🍕").font(.headline)
Spacer()
}.frame(height: 50)
}.tint(.brown)

HStack(spacing:0) {
Button(action: { startDeliveryPizza() }) {
VStack(spacing:0) {
Button(action: { showAllDeliveries() }) {
HStack {
Spacer()
Text("Start Ordering 👨🏻‍🍳").font(.headline)
Text("Show All Orders 🍕").font(.headline)
Spacer()
}.frame(height: 50)
}.tint(.blue)
Button(action: { updateDeliveryPizza() }) {
}.frame(height: 45)
}.tint(.brown)

HStack(spacing:0) {
Button(action: { startDeliveryPizza() }) {
HStack {
Spacer()
Text("Start Ordering 👨🏻‍🍳").font(.headline)
Spacer()
}.frame(height: 45)
}.tint(.blue)
Button(action: { updateDeliveryPizza() }) {
HStack {
Spacer()
Text("Update Order 🫠").font(.headline)
Spacer()
}.frame(height: 45)
}.tint(.purple)
}

Button(action: { stopDeliveryPizza() }) {
HStack {
Spacer()
Text("Update Order 🫠").font(.headline)
Text("Cancel Order 😞").font(.headline)
Spacer()
}.frame(height: 50)
}.tint(.purple)
}.frame(maxWidth: UIScreen.main.bounds.size.width)

Button(action: { stopDeliveryPizza() }) {
HStack {
Spacer()
Text("Cancel Order 😞").font(.headline)
Spacer()
}.frame(height: 50)
.padding(.bottom)
}.tint(.pink)
}.frame(height: 45)
}.tint(.pink)
}
.buttonStyle(.bordered)
.buttonBorderShape(.roundedRectangle(radius: 0))
.background(.thickMaterial)
.cornerRadius(25)
.padding(.horizontal,5)
}
.buttonStyle(.borderedProminent)
.buttonBorderShape(.roundedRectangle(radius: 0))
.ignoresSafeArea(edges: .bottom)
}

// MARK: - Functions
func startDeliveryPizza() {
print(ActivityAuthorizationInfo().areActivitiesEnabled)

let pizzaDeliveryAttributes = PizzaDeliveryAttributes(numberOfPizzas: 1, totalAmount:"$99")

let initialContentState = PizzaDeliveryAttributes.PizzaDeliveryStatus(driverName: "TIM 👨🏻‍🍳", estimatedDeliveryTime: Date()...Date().addingTimeInterval(15 * 60))
Expand All @@ -119,15 +125,24 @@ struct ContentView: View {
let deliveryActivity = try Activity<PizzaDeliveryAttributes>.request(
attributes: pizzaDeliveryAttributes,
contentState: initialContentState,
pushType: nil)
pushType: .token) // Enable Push Notification Capability First (from pushType: nil)

print("Requested a pizza delivery Live Activity \(deliveryActivity.id)")

showAlert = true
alertMsg = "Requested a pizza delivery Live Activity \(deliveryActivity.id)"


// Send the push token to server
Task {
for await pushToken in deliveryActivity.pushTokenUpdates {
let pushTokenString = pushToken.reduce("") { $0 + String(format: "%02x", $1) }
print(pushTokenString)

alertMsg = "Requested a pizza delivery Live Activity \(deliveryActivity.id)\n\nPush Token: \(pushTokenString)"
showAlert = true
}
}
} catch (let error) {
print("Error requesting pizza delivery Live Activity \(error.localizedDescription)")
alertMsg = "Error requesting pizza delivery Live Activity \(error.localizedDescription)"
showAlert = true
}
}
func updateDeliveryPizza() {
Expand Down Expand Up @@ -195,10 +210,14 @@ struct ContentView: View {
let deliveryActivity = try Activity<PizzaAdAttributes>.request(
attributes: pizzaAdAttributes,
contentState: initialContentState,
pushType: nil)
pushType: .token) // Enable Push Notification Capability First (from pushType: nil)
print("Requested a pizza ad Live Activity \(deliveryActivity.id)")
alertMsg = "Requested a pizza ad Live Activity \(deliveryActivity.id)"
showAlert = true
} catch (let error) {
print("Error requesting pizza ad Live Activity \(error.localizedDescription)")
alertMsg = "Error requesting pizza ad Live Activity \(error.localizedDescription)"
showAlert = true
}
}

Expand Down
7 changes: 7 additions & 0 deletions iOS16-Live-Activities/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@
</array>
<key>NSSupportsLiveActivities</key>
<true/>
<key>NSSupportsLiveActivitiesFrequentUpdates</key>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
</dict>
</plist>
2 changes: 2 additions & 0 deletions iOS16-Live-Activities/iOS16-Live-Activities.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.io.startway.iOS16-Live-Activities</string>
Expand Down
11 changes: 11 additions & 0 deletions iOS16-Live-Activities/iOS16_Live_ActivitiesApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ import SwiftUI

@main
struct iOS16_Live_ActivitiesApp: App {
init() {
// Set toolbar and navigation title text color white
let coloredAppearance = UINavigationBarAppearance()
coloredAppearance.configureWithOpaqueBackground()
coloredAppearance.backgroundColor = .clear
coloredAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
coloredAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
coloredAppearance.shadowColor = .clear
UINavigationBar.appearance().standardAppearance = coloredAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
}
var body: some Scene {
WindowGroup {
ContentView()
Expand Down

1 comment on commit c995012

@vercel
Copy link

@vercel vercel bot commented on c995012 Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

liveactivities-doc – ./

liveactivities-doc-1998code.vercel.app
liveactivities-doc-git-main-1998code.vercel.app
swiftpizza.vercel.app

Please sign in to comment.