Closed kimmy-wang closed 3 years ago
Could you please be a bit more specific what's not working?
Could you please be a bit more specific what's not working?
The content in the input box cannot be synchronized to the widget
Did you update the code with a appgroup id registered to your Apple developer account?
my code
import WidgetKit
import SwiftUI
import Intents
private let widgetGroupId = "group.com.upcwangying.flutter.app.gitter.widget"
struct Provider: IntentTimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), title: "Placeholder Title", message: "Placeholder Message", configuration: ConfigurationIntent())
}
func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let data = UserDefaults.init(suiteName:widgetGroupId)
let entry = SimpleEntry(date: Date(), title: data?.string(forKey: "title") ?? "No Title Set", message: data?.string(forKey: "message") ?? "No Message Set", configuration: configuration)
completion(entry)
}
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
getSnapshot(for: configuration, in: context) { (entry) in
let timeline = Timeline(entries: [entry], policy: .atEnd)
completion(timeline)
}
}
}
struct SimpleEntry: TimelineEntry {
let date: Date
let title: String
let message: String
let configuration: ConfigurationIntent
}
struct GitterHomeWidgetEntryView : View {
var entry: Provider.Entry
let data = UserDefaults.init(suiteName:widgetGroupId)
var body: some View {
VStack.init(alignment: .leading, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, content: {
Text(entry.title).bold().font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
Text(entry.message)
.font(.body)
.widgetURL(URL(string: "homeWidgetExample://message?message=\(entry.message)&homeWidget"))
}
)
}
}
@main
struct GitterHomeWidget: Widget {
let kind: String = "GitterHomeWidget"
var body: some WidgetConfiguration {
IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in
GitterHomeWidgetEntryView(entry: entry)
}
.configurationDisplayName("Gitter")
.description("Gitter for GitHub.")
}
}
struct GitterHomeWidget_Previews: PreviewProvider {
static var previews: some View {
GitterHomeWidgetEntryView(entry: SimpleEntry(date: Date(), title: "Example Title", message: "Example Message", configuration: ConfigurationIntent()))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}
Could you also post a screenshot of the Signing & Capabilities Section in Xcode to make sure the App Group is configured there as well. Plus the Flutter code where you setup the Widget and update the widget
Sorry, I misunderstood the iCloud containers in the app as app groups. It's normal now
How to implement the following code using objective-c
?
UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(60*15))
WorkmanagerPlugin.setPluginRegistrantCallback { registry in
GeneratedPluginRegistrant.register(with: registry)
}
The sample code is not working properly on ios.