Coder Social home page Coder Social logo

simonberner / ladi-simulator Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 480 KB

iOS 16 - Live Activities & Dynamic Island ๐Ÿ๏ธ

License: MIT License

Swift 100.00%
activitykit dynamicisland liveactivities widgetkit modelview delegationpattern

ladi-simulator's Introduction

Live Activities & Dynamic Island Simulator

mastodon.green/@simonberner Gitmoji Conventional Commits

A little basketball 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 island Dynamic 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 View Banner iPhone 14 Banner iPhone 14 Pro
LADI iPhone14Pro LADI expanded iPhone14Pro

Architecture

The App Architecture is built using the following patterns:

I am using the Model-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 the Start Game Simulation, the GameSimulator "factory" spits out a new GameState every 2 seconds. It is restricted to be started only once.
  • By pressing Start 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 some boilerplate 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 to True.
  • Use the new (iOS 16.2+) struct ActivityContent<State> to describe the current state and config of a LA.
  • UI Banner on the Always-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 use AnyObject 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, see here

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 issues Closes #1, Resolves #2, Fixes #3. credits

Contribution Guidelines

Unit-Testing

Follow the Arrange, 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 the Given-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 this guide.

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

ladi-simulator's People

Contributors

ripeliz avatar simonberner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ladi-simulator's Issues

LA: add background updates

Issue:
The App is running in the foreground: if we pull down the lock screen the Live Activity is shown in the banner. But as soon we go to the Home-Screen, the App goes into the background and the Live Activity in the Dynamic Island stops running.

Possible Solutions:

  • Add new capability: Background Modes (but be aware of that the App has to have good reasons to BE ALLOWED of running in the background and doing updates, otherwise the AppStore reviewers will reject the App!) Apple does not want that every App can just do stuff in the background and drain users battery.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.