-
Notifications
You must be signed in to change notification settings - Fork 43
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
Can't I use LiveActivityIntent? #62
Comments
To update a Live Activity you need to do something in the perform function struct RefreshIntent: LiveActivityIntent {
static var title: LocalizedStringResource = "Refresh"
static var description = IntentDescription("Refresh Description.")
func perform() async throws -> some IntentResult {
// live activity update ??
return .result()
}
} for example you could call an API and then update the UserDefaults Heres an example: @available(iOS 17.0, *)
struct ReloadDataAppIntent:AppIntent{
@Parameter(title: "id")
var id:String
init() {
id = ""
}
init(id: String) {
self.id = id
}
static var title: LocalizedStringResource = "ReloadData"
func perform() async throws -> some IntentResult {
@StateObject var viewModel = ReloadDataViewModel()
let sharedDefault = UserDefaults(suiteName: "YOURGROUPNAME")!
data = await viewModel.fetchData(apiKey:"YOURAPIKEY)
sharedDefault.set(YOURDATA, forKey: "YOURKEY")
WidgetCenter.shared.reloadAllTimelines()
return .result()
}
} Then in a button you can do
|
@Elliot727 Thank you reply, @StateObject var viewModel = ReloadDataViewModel()
let sharedDefault = UserDefaults(suiteName: "YOURGROUPNAME")!
data = await viewModel.fetchData(apiKey:"YOURAPIKEY)
sharedDefault.set(YOURDATA, forKey: "YOURKEY")
WidgetCenter.shared.reloadAllTimelines()
return .result() Because it creates live activity with the flutter code.. |
Let me explain. Hope this helps
Please replace placeholders like "YOURGROUPNAME," "YOURAPIKEY," "YOURDATA," and "YOURKEY" with your actual values as needed. Let Me Know if you need anything else explained Also its best to learn Swift / SwiftUI when building the iOS widgets |
hi! Thanks for the great work!
I want to use interactivity live activity using LiveActivityIntent.
But, I don't know how to refresh in swift code.
Can I update the live activity in swift (widget file) rather than flutter code?
This is a sample code
Thank you 🙇
https://developer.apple.com/documentation/AppIntents/LiveActivityIntent
The text was updated successfully, but these errors were encountered: