added live activity widget
parent
1f40644806
commit
5e93423dac
@ -0,0 +1,16 @@
|
||||
//
|
||||
// AppWidgetBundle.swift
|
||||
// AppWidget
|
||||
//
|
||||
// Created by Cloud Solutions on 15/12/2025.
|
||||
//
|
||||
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct AppWidgetBundle: WidgetBundle {
|
||||
var body: some Widget {
|
||||
AppWidgetLiveActivity()
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
//
|
||||
// AppWidgetLiveActivity.swift
|
||||
// AppWidget
|
||||
//
|
||||
// Created by Cloud Solutions on 15/12/2025.
|
||||
//
|
||||
|
||||
import ActivityKit
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
struct LiveActivitiesAppAttributes: ActivityAttributes, Identifiable {
|
||||
public typealias LiveDeliveryData = ContentState // don't forget to add this line, otherwise, live activity will not display it.
|
||||
|
||||
public struct ContentState: Codable, Hashable { }
|
||||
|
||||
var id = UUID()
|
||||
}
|
||||
extension LiveActivitiesAppAttributes {
|
||||
func prefixedKey(_ key: String) -> String {
|
||||
return "\(id)_\(key)"
|
||||
}
|
||||
}
|
||||
|
||||
let sharedDefault = UserDefaults(suiteName: "group.alhabib.pateientApp")!
|
||||
struct AppWidgetAttributes: ActivityAttributes {
|
||||
public struct ContentState: Codable, Hashable {
|
||||
// Dynamic stateful properties about your activity go here!
|
||||
var emoji: String
|
||||
}
|
||||
|
||||
// Fixed non-changing properties about your activity go here!
|
||||
var name: String
|
||||
}
|
||||
|
||||
struct AppWidgetLiveActivity: Widget {
|
||||
|
||||
var body: some WidgetConfiguration {
|
||||
ActivityConfiguration(for: LiveActivitiesAppAttributes.self) { context in
|
||||
// Lock screen/banner UI goes here
|
||||
VStack {
|
||||
Text("Hello patient")
|
||||
}
|
||||
.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")
|
||||
}
|
||||
|
||||
} compactLeading: {
|
||||
Text("Leading")
|
||||
} compactTrailing: {
|
||||
Text("trailing")
|
||||
} minimal: {
|
||||
Text("minimal")
|
||||
}
|
||||
.widgetURL(URL(string: "http://www.apple.com"))
|
||||
.keylineTint(Color.red)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
extension AppWidgetAttributes {
|
||||
fileprivate static var preview: AppWidgetAttributes {
|
||||
AppWidgetAttributes(name: "World")
|
||||
}
|
||||
}
|
||||
|
||||
extension AppWidgetAttributes.ContentState {
|
||||
fileprivate static var smiley: AppWidgetAttributes.ContentState {
|
||||
AppWidgetAttributes.ContentState(emoji: "😀")
|
||||
}
|
||||
|
||||
fileprivate static var starEyes: AppWidgetAttributes.ContentState {
|
||||
AppWidgetAttributes.ContentState(emoji: "🤩")
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
<?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>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.alhabib.patientApp</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
Loading…
Reference in New Issue