Create a Live Activity with ActivityKit & WidgetKit for iOS 16
HTML-код
- Опубликовано: 13 окт 2024
- Learn how to create a live lock screen widget for your iOS 16 app using WidgetKit and ActivityKit! This video uses Xcode 14 Beta 4, so expect changes over the next months.
Sponsor Links:
Try Adapty: adapty.io/
Adapty iOS SDK: github.com/ada...
Join the mobile devs community : / discord
Documentation: developer.appl...
WidgetKit Course: • WidgetKit Course
👋 Links: flowritesco.de
🛠 Forge: apple.co/3riG8MQ
🚀 LaunchBuddy: apple.co/3iFcjjW
Affiliate Links ❤
📕 SwiftUI & Combine Books: www.bigmountai...
🔬 Get Reports about your apps: appfigures.com...
📊 Privacy focused analytics: dashboard.tele...
💻 The most powerful mac app for developers: devutils.app/?...
☕️ Support me: ko-fi.com/flow...
If you have any video suggestions please feel free to let me know by a comment.
Get in contact via
Twitter: / flowritescode
This was a great territorial and I was able to successfully implement a Live Activity in my app. Thank you for providing this. It was super short and to the point.
well done, I am looking at converting my widgets to Live Activities, glad I found this video. Keep it up!
Great video Flo! Thanks for sharing 🙌
When you create this optional variable activity you don't need to set it to nil as it is nil by default, is it any different when it's @State? 🤔
You’re absolutely right, that isn’t needed! I just like to be very specific, that’s why I always specify the type and nil :D
How updateActivity function getting called ?, in video I can only see declaration and body of function
Great vid as always Flo!
Thank you Dave!
Hey Flo Could you please provide guidance on how to display real-time time in a widget ?
I don't think you can really do that. My only idea would be looking at Text (date, style: ...) to see if there's an option for that.
Thank you for this video. This was very helpful. A question, how can we show a Live Activity update on the Home Screen on devices with no Dynamic Island?
In Apple documentation, it states this can be done but I am not sure how to achieve this? Have you done this before? Thank you
Hey Rahul - glad it was helpful.
Are you referring to live activities on the lock screen for devices without the dynamic island? "Live home screen widgets" don't exist, unfortunately. Instead you can force iOS to update your home screen widgets through the WidgetCenter API in your main app.
@ 8:04 the ActivityConfureation looks different in Xcode as I have a dynamic Island option
Can you show how that show be configured using the "(for: _.Type, content: (
Yup, I have another video all about that topic: ruclips.net/video/AUOoalBwxos/видео.html
Can I implement this in UIKit project? Thank for sharing!
Yes you can! But the UI inside the Widget Extension has to be SwiftUI. The UI framework of your main app doesn't matter :)
Hello @Flo writes Code ,
Its a great tutorial and i implemented this in new app its working fine but when i do the same code in my old Obj. C Project the live activity not going to be shown there is no error or warning i am getting what will be the issue can you assist me on that.
Thank you. I have never worked with Objective-C so I can't help there, sorry.
Thank you so much for this video it was exactly the information I needed! I have question about the background color of the lock screen widget. I'm trying to change the background to a red, but maintain the signature apple semi-transparency. When I attempt to use .activityBackgroundTint(), it changes the color to red, but loses the semi-transparency. Is there a way to solve this?
Glad it was helpful! I don't think there is a system API for colored materials. You could play around with a ZStack with a color as the base layer. Then you could reduce the opacity of that color to match what you want to achieve.
Thanks for that… One question: Do you have any tutorials on updating the LiveActivity using URLSession Requests let’s say every 60 seconds?
Are you referring to your app being in the foreground or background? You can only update a LiveActivity from your app while it's in the foreground. Alternatively you can update them using a push notification while your app is in the background. I haven't worked with that myself though, so I'm not sure how complex it is to set up.
@@FloWritesCode Hey Flo, i was wondering what the best way to set up a push notification is? I am looking at some of the documentation for ios 16.2 and I figured out a lot of the frontend for live activities, but it seems like apple deprecated a lot of the functions for the backend. I was wondering if you have experiment with any dynamic data to push to the notifications?
@@FloWritesCode also a lot of their documentation for push notifications does not seem to make sense to me and it would be nice if you made a video over dynamic backend data.
Hi, How to display the timer in minutes like 7 mins , 6 mins count down?
I just had a look around the documentation, but I honestly don't know... Let us know if you figure it out!
How can i create multiple live activities for a single app? Then how would we distinguish between say two activities, which one to call update and end after starting both?
I have been trying to create instances but not successful
I'm not sure, you'll have to dig into the documentation for that. I think it's pretty comprehensive though :)
Hi 👋 Do you think iOS development is good for full time freelancing? Lot of ppl saying that web is only best way to be freelancer.
I'm not doing any freelancing, but I'm sure there are plenty of people who live from it. It's probably easiest to learn about this on Twitter by following iOS developers (especially indies).
Thanks for the video. My question is; do user have to open the application, or will we be able to create the activity from remove notification? For example, on a live score activity, I would like to user get the activity automatically when the match starts, because I will send the remote notification for the activity to start.
Yes, that is possible! This video just shows how you can manage Activities from within the app, but you can also do this via push notifications. I would recommend you to have a look at the documentation, as this actually looks pretty nicely documented to me.
Very detailed 💌
Thank you!
Can i use the same Live Activity in UIKit(SWIFT) project if any kindly share me the proper resources.
Yup, this is the same setup for SwiftUI and UIKit. Just keep in mind that WidgetKit only supports SwiftUI.View, not UIKit.UIView.
Wow thanks for the great video!
Glad you like it!
Hey can please HELP MEE!!!!!
I want to create a lock screen widget and i create it. But i just need one additional thing i want that when clicked on widget the widget should not open the app (Which it is opening). It should run certain that like making a call to the api.
Can please any one help me how i can achieve this task i have searched all over th
e internet but didn't found any solution.
PLEASE HELP MEE!!!!!
How can I display a network image in Live Activity?
Download the data using URLSession and turn it into a UIImage. You can then use it to create an Image.
@@FloWritesCode Hello. I do work in react-native need show image url in live activity?. Help me! thx
I don’t know how implement a Timer in live activities because when the widget is updated the counter returns to 0, can u help me?
If you share your code I might be able to help :)
i get like 3 swift files when make a new widget
Yes, the autogenerated files have changed. Their content is mostly the same as before though, except for a WidgetBundle, which you don't need to worry about :)
Have anyone tried using stale date