Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

iOS 16 - Live Activities & Dynamic Island 🏝️

License

NotificationsYou must be signed in to change notification settings

simonberner/ladi-simulator

Repository files navigation

mastodon.green/@simonbernerGitmojiConventional Commits

A littlebasketball game simulator which generates some mock data to show how that live data can be displayed with live activities on the lock screen and in the dynamic island.


Contents


Functionality

This App shows Live Activity (live data updates):

  • On the lock screen and on devices that don't support the Dynamic Island, a banner on top of the screen.
  • in the compact version of the dynamic island
  • in the expanded version of the dynamic islandDynamic Island: On devices that support the Dynamic Island (see list below), the App displays Live Activities on the leading and trailing side of the TrueDepth camera.

Definitions

Tech Stack

  • Xcode 14.2
  • Swift 5.7.2

Frameworks

Device and OS Compatibility

LAs are iPhone only.

  • For LA: iPhone with iOS 16.1+
  • For DI: iPhone 14 Pro/Pro Max with iOS 16.1+

Screenshots

App ViewBanner iPhone 14Banner iPhone 14 Pro
LADI iPhone14ProLADI expanded iPhone14Pro

Architecture

The App Architecture is built using the following patterns:

I am using theModel-View architectural pattern in order that the GameView can observe/listen to state changes in the GameModel and rerender its UI accordingly.

I am using the following design patterns to solve common challenges:

How does it work?

  • By pressing theStart Game Simulation, the GameSimulator "factory" spits out a new GameState every 2 seconds. It is restricted to be started only once.
  • By pressingStart Live Activity, the Live Activity can be started. It is restricted to be started only once.
  • The Live Activity updates while the App is running in the background. This is only possible because the background mode 'Audio, AirPlay,...' is enabled.
  • The GameView and the Live Activity updates with every (new) GameState change
  • The GameModel is (the glue) between the GameView and the GameSimulator
  • The GameSimulator stops automatically after 120 ball possessions in total

Learnings

Live Activities

  • Apple doc: Displaying live data
  • Live activities can live for up to 8 hours at max.
  • Completed (final state) Live Activity will stay on the Lock Screen for 4 hours.
  • Live Activity has to be launched while the App is in the foreground.
  • Live Activity can be updated while the App is running in the background.
  • Live Activities are not Widgets but we need WidgetKit to build them with Widget Extension.
  • It is highly likely that one is going to have also a Widget in combination with Live Activities.
  • Live Activity vs Widget: a Widget can update itself, as a LA have to be updated from within the App.
  • As soon you create a Widget Extension including LA, Xcode will generate someboilerplate code for you.
  • When more than one LA is active the system chooses which LAs are visible and displays two using the minimal presentation
  • IMPORTANT: In the App Target in the Info.plist we have to add the Key:Supports Live Activities and set its value toTrue.
  • Use the new (iOS 16.2+) structActivityContent<State> to describe the current state and config of a LA.
  • UI Banner on theAlways-On display (iPhone 14 only) doesn't show any animations
  • UI Banner on the regular lock screen shows animations

Live Activities - Background Updates

Any, AnyObject, any

AnyObject

  • All classes, class types, or class-only protocols can useAnyObject as their concrete type.
  • If possible try to use concrete types as it is more readable to your friends.
  • By using it as our destination, we always need to cast and consider casting failures using the default implementation.
  • Try to use concrete protocol instead, seehere

Any

any

Type Erasure

Nice to know

  • Architecture vs Architectural Patterns vs Design Patterns
  • Architecture: An architecture shows how we organize our code, or how the system will look like from 10000 meters above from the highest level of abstraction of our system design.
  • Architecture: Software architecture refers to the fundamental structure underlying a system. It is the general conceptual design that informs the development and maintenance of software and defines what it can — and cannot — do.
  • Architecture: A poor architecture can make changes to the software much harder than they need to be.
  • Architectural Patterns: Are broad solutions how we can implement the chosen architecture.
  • Design Patterns: Are accumulative best practices and experiences that developers used over the years to solve general problems.
  • GitHub: We can use one of the following keywords to close an issue via a commit message:close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved. The message MUST contain a string matching the following pattern:KEYWORD #ISSUENO. For example:Closes/closes #1 or multiple issuesCloses #1, Resolves #2, Fixes #3.credits

Contribution Guidelines

Unit-Testing

Follow theArrange, Act and Assert Pattern for Unit Testing.

  • Arrange inputs and targets:
    • Does the test require any objects or special settings?
    • Does it need to prep a database?
    • Does it need to log into a web app?
  • Act on target behavior:
    • This step should call the function/method/API, or whatever needs to be tested.
    • It should focus on the target behavior.
  • Assert expected outcomes:
    • This step should elicit some sort of response.
    • Then the response should be judged for correctness.

UI-Testing

Follow theGiven-When-Then style to write the UI-Tests from a user perspective.

Code Comments

  • Include "self documenting code."
  • Additionally, include descriptive comments in order to improve readability.-Aim for comments that allow other programmers to understand your code without having to work through your entire classes/methods.

Pull Requests

  • Pull requests should be kept to a reasonable size.
  • Pull requests should be descriptive, answer the following questions:
    • What was the problem?
    • What did you do to improve it?
    • How do you know it is a working solution?/What tests did you do?
    • Why do you believe this is the right solution?
    • Why is this the best solution for the problem?
  • Review/proofread your pull request before submission.Following thisguide.

References

Credits

🙏🏽 Sean Allen

Extra: Xcode shortcuts

  • CMD + B: build the project
  • CMD + R: build and run the App in the simulator
  • CMD + SHIFT + K: clean build folder
  • CMD + SHIFT + O: open quick search
  • CMD + SHIFT + J: highlight the selected open file in the navigator
  • CMD + SHIFT + L: open up the library (Snippets, Media, Colors, SF Symbols)

Made with a 🙂Simon Berner

Releases

No releases published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp