Dynamic Island is master stroke from Apple in iOS 16. Tremendous look!
Dynamic Island is almost same as a widget setup. I will describe you the sample code to setup the Dynamic Island
Let’s Create Project
I have created a new project of SwiftUI which create a live activity and this activity is connected with Dynamic Island.
Live Activities display your appβs most current data on the iPhone Lock Screen and in the Dynamic Island.
Note: Following step is must required. Set YES in Supports Live Activities into your app’s info plist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now I have created a sample attributes file which will help us to display content on the activity and dynamic island.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now I have added a widget for the live activity which will be useful for dynamic island. For that I have added a widget extension.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here LiveActivityExpandedViewSample will display status when dynamic island is in expanded state and on lock screen of iPhone. ( iPhone 14 Pro π )
Dynamic Island have 4 areas in which I can display my content. i.e. center, leading, trailing and bottom as I have described in sample code above.
Request Activity
Now from main application I have created an activity which will display the dynamic island with live activity on lock screen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters