Skip to content

Commit b149866

Browse files
committed
Adding support for Live activties in Advanced sample app
1 parent b892c74 commit b149866

File tree

15 files changed

+1076
-103
lines changed

15 files changed

+1076
-103
lines changed

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

Lines changed: 418 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>
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 WidgetKit
16+
import AppIntents
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: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 WidgetKit
16+
import SwiftUI
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, in context: Context) async -> SimpleEntry {
24+
SimpleEntry(date: Date(), configuration: configuration)
25+
}
26+
27+
func timeline(for configuration: ConfigurationAppIntent, in context: Context) async -> Timeline<SimpleEntry> {
28+
var entries: [SimpleEntry] = []
29+
30+
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
31+
let currentDate = Date()
32+
for hourOffset in 0 ..< 5 {
33+
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
34+
let entry = SimpleEntry(date: entryDate, configuration: configuration)
35+
entries.append(entry)
36+
}
37+
38+
return Timeline(entries: entries, policy: .atEnd)
39+
}
40+
}
41+
42+
struct SimpleEntry: TimelineEntry {
43+
let date: Date
44+
let configuration: ConfigurationAppIntent
45+
}
46+
47+
struct SampleLiveActivityEntryView : View {
48+
var entry: Provider.Entry
49+
50+
var body: some View {
51+
VStack {
52+
Text("Time:")
53+
Text(entry.date, style: .time)
54+
55+
Text("Favorite Emoji:")
56+
Text(entry.configuration.favoriteEmoji)
57+
}
58+
}
59+
}
60+
61+
struct SampleLiveActivity: Widget {
62+
let kind: String = "SampleLiveActivity"
63+
64+
var body: some WidgetConfiguration {
65+
AppIntentConfiguration(kind: kind, intent: ConfigurationAppIntent.self, provider: Provider()) { entry in
66+
SampleLiveActivityEntryView(entry: entry)
67+
.containerBackground(.fill.tertiary, for: .widget)
68+
}
69+
}
70+
}
71+
72+
extension ConfigurationAppIntent {
73+
fileprivate static var smiley: ConfigurationAppIntent {
74+
let intent = ConfigurationAppIntent()
75+
intent.favoriteEmoji = "😀"
76+
return intent
77+
}
78+
79+
fileprivate static var starEyes: ConfigurationAppIntent {
80+
let intent = ConfigurationAppIntent()
81+
intent.favoriteEmoji = "🤩"
82+
return intent
83+
}
84+
}
85+
86+
#Preview(as: .systemSmall) {
87+
SampleLiveActivity()
88+
} timeline: {
89+
SimpleEntry(date: .now, configuration: .smiley)
90+
SimpleEntry(date: .now, configuration: .starEyes)
91+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 WidgetKit
16+
import SwiftUI
17+
18+
@main
19+
struct SampleLiveActivityBundle: WidgetBundle {
20+
var body: some Widget {
21+
SampleLiveActivity()
22+
SampleLiveActivityLiveActivity()
23+
}
24+
}

0 commit comments

Comments
 (0)