Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Advanced test app with live activity support #14099

Merged
merged 8 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSSupportsLiveActivities</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
2 changes: 1 addition & 1 deletion FirebaseMessaging/Apps/AdvancedSample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ target 'AppClips' do
end

target 'SampleWatchWatchKitExtension' do
platform :watchos, '6.0'
platform :watchos, '7.0'
shared_pods
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import AppIntents
import WidgetKit

struct ConfigurationAppIntent: WidgetConfigurationIntent {
static var title: LocalizedStringResource = "Configuration"
static var description = IntentDescription("This is an example widget.")

// An example configurable parameter.
@Parameter(title: "Favorite Emoji", default: "😃")
var favoriteEmoji: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-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>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import SwiftUI
import WidgetKit

struct Provider: AppIntentTimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), configuration: ConfigurationAppIntent())
}

func snapshot(for configuration: ConfigurationAppIntent,
in context: Context) async -> SimpleEntry {
SimpleEntry(date: Date(), configuration: configuration)
}

func timeline(for configuration: ConfigurationAppIntent,
in context: Context) async -> Timeline<SimpleEntry> {
var entries: [SimpleEntry] = []

// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 5 {
let entryDate = Calendar.current.date(
byAdding: .hour,
value: hourOffset,
to: currentDate
)!
let entry = SimpleEntry(date: entryDate, configuration: configuration)
entries.append(entry)
}

return Timeline(entries: entries, policy: .atEnd)
}
}

struct SimpleEntry: TimelineEntry {
let date: Date
let configuration: ConfigurationAppIntent
}

struct SampleLiveActivityEntryView: View {
var entry: Provider.Entry

var body: some View {
VStack {
Text("Time:")
Text(entry.date, style: .time)

Text("Favorite Emoji:")
Text(entry.configuration.favoriteEmoji)
}
}
}

struct SampleLiveActivity: Widget {
let kind: String = "SampleLiveActivity"

var body: some WidgetConfiguration {
AppIntentConfiguration(
kind: kind,
intent: ConfigurationAppIntent.self,
provider: Provider()
) { entry in
SampleLiveActivityEntryView(entry: entry)
.containerBackground(.fill.tertiary, for: .widget)
}
}
}

private extension ConfigurationAppIntent {
static var smiley: ConfigurationAppIntent {
let intent = ConfigurationAppIntent()
intent.favoriteEmoji = "😀"
return intent
}

static var starEyes: ConfigurationAppIntent {
let intent = ConfigurationAppIntent()
intent.favoriteEmoji = "🤩"
return intent
}
}

#Preview(as: .systemSmall) {
SampleLiveActivity()
} timeline: {
SimpleEntry(date: .now, configuration: .smiley)
SimpleEntry(date: .now, configuration: .starEyes)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import SwiftUI
import WidgetKit

@main
struct SampleLiveActivityBundle: WidgetBundle {
var body: some Widget {
SampleLiveActivity()
SampleLiveActivityLiveActivity()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import ActivityKit
import SwiftUI
import WidgetKit

struct SampleLiveActivityAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable {
enum LVStatus: Float, Codable, Hashable {
case started = 0
case inProgress = 1
case completed = 2

var description: String {
switch self {
case .started:
return "Your Live Activity is started!"
case .inProgress:
return "Your Live Activity is in progress!"
case .completed:
return "Your Live activity is completed!"
}
}
}

let status: LVStatus
}

// Fixed non-changing properties about your activity go here!
var lvInstanceNumber: Double
}

struct SampleLiveActivityLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: SampleLiveActivityAttributes.self) { context in
// Lock screen/banner UI goes here
VStack {
SampleLiveActivityView(context: context)
}
.activityBackgroundTint(Color.cyan)
.activitySystemActionForegroundColor(Color.black)

} dynamicIsland: { context in
DynamicIsland {
// Expanded UI goes here. Compose the expanded UI through
// various regions, like leading/trailing/center/bottom
DynamicIslandExpandedRegion(.leading) {
Text("Leading")
}
DynamicIslandExpandedRegion(.trailing) {
Text("Trailing")
}
DynamicIslandExpandedRegion(.bottom) {
Text("Bottom")
// more content
}
} compactLeading: {
Text("L")
} compactTrailing: {
Text("T")
} minimal: {
Text("M")
}
.widgetURL(URL(string: "http://www.apple.com"))
.keylineTint(Color.red)
}
}
}

private extension SampleLiveActivityAttributes {
static var preview: SampleLiveActivityAttributes {
SampleLiveActivityAttributes(lvInstanceNumber: 1)
}
}

private extension SampleLiveActivityAttributes.ContentState {
static var stateStarted: SampleLiveActivityAttributes.ContentState {
SampleLiveActivityAttributes.ContentState(status: LVStatus.started)
}

static var stateInProgress: SampleLiveActivityAttributes.ContentState {
SampleLiveActivityAttributes.ContentState(status: LVStatus.inProgress)
}

static var stateCompleted: SampleLiveActivityAttributes.ContentState {
SampleLiveActivityAttributes.ContentState(status: LVStatus.completed)
}
}

#Preview("Notification", as: .content, using: SampleLiveActivityAttributes.preview) {
SampleLiveActivityLiveActivity()
} contentStates: {
SampleLiveActivityAttributes.ContentState.stateStarted
SampleLiveActivityAttributes.ContentState.stateInProgress
SampleLiveActivityAttributes.ContentState.stateCompleted
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import SwiftUI
import WidgetKit

struct SampleLiveActivityView: View {
let context: ActivityViewContext<SampleLiveActivityAttributes>

var body: some View {
VStack {
HStack {
Image(systemName: "cup.and.saucer")
ProgressView(value: context.state.status.rawValue, total: 2)
.tint(.black)
.background(Color.brown)
Image(systemName: "cup.and.saucer.fill")
}
.padding(16)

Text("\(context.state.status.description)")
.font(.system(size: 18, weight: .semibold))
.padding(.bottom)
Text("Instance No: " + String(context.attributes.lvInstanceNumber))
.font(.system(size: 18, weight: .semibold))
.padding(.bottom)
Spacer()
}
.background(Color.brown.opacity(0.6))
}
}
2 changes: 1 addition & 1 deletion FirebaseMessaging/Apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ the sample code. The one inside the AdvancedSample folder is a test app
based on the test app in the Sample folder. Both Apps share most of the
code in the main target. The AdvancedSample app provides advanced app
extensions features, such as Notification Service Extension, Shared
Extension, App Clips and a watchOS app. The advanced sample app has more
Extension, App Clips, Live Activites and a watchOS app. The advanced sample app has more
targets than the Sample app and requires your own provisioning profiles and
certificates for each extension target to be setup so that it can be run on
a real device.
Expand Down
4 changes: 4 additions & 0 deletions FirebaseMessaging/Apps/Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
Text("Topic")
.fontWeight(.semibold)
}
NavigationLink(destination: LiveActivityView()) {

Check failure on line 61 in FirebaseMessaging/Apps/Shared/ContentView.swift

View workflow job for this annotation

GitHub Actions / messaging-sample-build-test

cannot find 'LiveActivityView' in scope

Check failure on line 61 in FirebaseMessaging/Apps/Shared/ContentView.swift

View workflow job for this annotation

GitHub Actions / messaging-swiftui-sample-build-test

cannot find 'LiveActivityView' in scope
Text("Live Activity")
.fontWeight(.semibold)
}

// MARK: Action buttons

Expand Down
Loading
Loading