Skip to content

Commit 33f8419

Browse files
authored
Updating Advanced test app with live activity support (#14099)
1 parent 07aeb8b commit 33f8419

File tree

17 files changed

+997
-8
lines changed

17 files changed

+997
-8
lines changed

FirebaseMessaging/Apps/AdvancedSample/AdvancedSample.xcodeproj/project.pbxproj

Lines changed: 420 additions & 6 deletions
Large diffs are not rendered by default.

FirebaseMessaging/Apps/AdvancedSample/AdvancedSample/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<string>1</string>
2121
<key>LSRequiresIPhoneOS</key>
2222
<true/>
23+
<key>NSSupportsLiveActivities</key>
24+
<true/>
2325
<key>UIApplicationSceneManifest</key>
2426
<dict>
2527
<key>UIApplicationSupportsMultipleScenes</key>

FirebaseMessaging/Apps/AdvancedSample/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ target 'AppClips' do
2929
end
3030

3131
target 'SampleWatchWatchKitExtension' do
32-
platform :watchos, '6.0'
32+
platform :watchos, '7.0'
3333
shared_pods
3434
end
3535

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import AppIntents
16+
import WidgetKit
17+
18+
struct ConfigurationAppIntent: WidgetConfigurationIntent {
19+
static var title: LocalizedStringResource = "Configuration"
20+
static var description = IntentDescription("This is an example widget.")
21+
22+
// An example configurable parameter.
23+
@Parameter(title: "Favorite Emoji", default: "😃")
24+
var favoriteEmoji: String
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"platform" : "ios",
6+
"size" : "1024x1024"
7+
}
8+
],
9+
"info" : {
10+
"author" : "xcode",
11+
"version" : 1
12+
}
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSExtension</key>
6+
<dict>
7+
<key>NSExtensionPointIdentifier</key>
8+
<string>com.apple.widgetkit-extension</string>
9+
</dict>
10+
</dict>
11+
</plist>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import SwiftUI
16+
import WidgetKit
17+
18+
struct Provider: AppIntentTimelineProvider {
19+
func placeholder(in context: Context) -> SimpleEntry {
20+
SimpleEntry(date: Date(), configuration: ConfigurationAppIntent())
21+
}
22+
23+
func snapshot(for configuration: ConfigurationAppIntent,
24+
in context: Context) async -> SimpleEntry {
25+
SimpleEntry(date: Date(), configuration: configuration)
26+
}
27+
28+
func timeline(for configuration: ConfigurationAppIntent,
29+
in context: Context) async -> Timeline<SimpleEntry> {
30+
var entries: [SimpleEntry] = []
31+
32+
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
33+
let currentDate = Date()
34+
for hourOffset in 0 ..< 5 {
35+
let entryDate = Calendar.current.date(
36+
byAdding: .hour,
37+
value: hourOffset,
38+
to: currentDate
39+
)!
40+
let entry = SimpleEntry(date: entryDate, configuration: configuration)
41+
entries.append(entry)
42+
}
43+
44+
return Timeline(entries: entries, policy: .atEnd)
45+
}
46+
}
47+
48+
struct SimpleEntry: TimelineEntry {
49+
let date: Date
50+
let configuration: ConfigurationAppIntent
51+
}
52+
53+
struct SampleLiveActivityEntryView: View {
54+
var entry: Provider.Entry
55+
56+
var body: some View {
57+
VStack {
58+
Text("Time:")
59+
Text(entry.date, style: .time)
60+
61+
Text("Favorite Emoji:")
62+
Text(entry.configuration.favoriteEmoji)
63+
}
64+
}
65+
}
66+
67+
struct SampleLiveActivity: Widget {
68+
let kind: String = "SampleLiveActivity"
69+
70+
var body: some WidgetConfiguration {
71+
AppIntentConfiguration(
72+
kind: kind,
73+
intent: ConfigurationAppIntent.self,
74+
provider: Provider()
75+
) { entry in
76+
SampleLiveActivityEntryView(entry: entry)
77+
.containerBackground(.fill.tertiary, for: .widget)
78+
}
79+
}
80+
}
81+
82+
private extension ConfigurationAppIntent {
83+
static var smiley: ConfigurationAppIntent {
84+
let intent = ConfigurationAppIntent()
85+
intent.favoriteEmoji = "😀"
86+
return intent
87+
}
88+
89+
static var starEyes: ConfigurationAppIntent {
90+
let intent = ConfigurationAppIntent()
91+
intent.favoriteEmoji = "🤩"
92+
return intent
93+
}
94+
}
95+
96+
#Preview(as: .systemSmall) {
97+
SampleLiveActivity()
98+
} timeline: {
99+
SimpleEntry(date: .now, configuration: .smiley)
100+
SimpleEntry(date: .now, configuration: .starEyes)
101+
}

0 commit comments

Comments
 (0)