How to Build a Smooth Live Activity Timer for iOS Using Expo and Swift
Scale AI confirms 'significant' investment from Meta, CEO Alexandr Wang stepping down On Friday, data-labeling company Scale AI announced a substantial investment from Meta, which values the startup at $29 billion. Scale’s co-founder and CEO, Alexandr Wang, is leaving his role to join Meta's AI division, specifically to support the company's superintelligence efforts. This move signals a major strategic shift in the tech landscape, as Meta aims to bolster its AI capabilities amidst intense competition from rivals like Google, OpenAI, and Anthropic. The Investment Details Reports indicate that Meta invested approximately $14.3 billion for a 49% stake in Scale AI. This significant investment underscores the critical role that high-quality training data plays in the development of advanced AI models, particularly those used in generative AI. Scale AI is renowned for its data annotation services, which help train large language models and other AI applications. The partnership is designed to integrate Scale's expertise into Meta's ongoing AI projects. Scale AI's Transition With Wang stepping down, Jason Droege, Scale’s current Chief Strategy Officer, will take over as interim CEO. Scale AI emphasized that despite the investment, it will remain an independent entity. Wang will continue to serve on the company’s board of directors, ensuring a continued influence on its strategic direction. The funds from Meta will be used to pay investors and shareholders, as well as to fuel further growth and innovation at Scale. Why It Matters for Meta Meta's investment in Scale AI is a direct response to the rapid advancements in AI by competitors. The social media giant has been lagging behind in the race to develop cutting-edge AI models, and this partnership represents a strategic move to catch up. According to data from SignalFire, Meta lost 4.3% of its top AI talent to other labs last year, highlighting the company's need to strengthen its internal AI capabilities. Industry Reactions Industry insiders view this investment as a sign of Meta's renewed commitment to AI. The large sum and significant equity stake demonstrate Meta’s willingness to invest heavily in foundational technologies. By leveraging Scale AI’s expertise, Meta hopes to accelerate its AI research and development, ultimately enhancing its products and services with more sophisticated AI features. Company Profile: Scale AI Scale AI is a leading provider of data labeling and annotation services, crucial for training machine learning models. Founded in 2016 by Alexandr Wang, the company has raised over $1 billion in previous funding rounds, including investments from Amazon and Meta. Scale has been instrumental in supporting the development of AI models for some of the world's top tech companies. Building a Live Activity Timer in Expo Live Activities on iOS have the potential to revolutionize user engagement by providing real-time updates directly on the Lock Screen or Dynamic Island. As a developer, the prospect of integrating a live workout timer into my app was incredibly exciting. However, Live Activities are built using Apple’s native tools, like Swift and ActivityKit, which initially seemed daunting for an Expo project. Fortunately, I discovered expo-apple-targets, a package that significantly eased the integration process. Why Live Activities Caught My Attention Live Activities are more than just a cool feature; they offer a VIP pass to the most important updates in your app without requiring users to unlock their phones. For a fitness app, imagine a timer that keeps track of your plank duration mid-workout, visible on the Lock Screen. This level of visibility can keep users motivated and engaged without the friction of opening the app. The Solution: Expo-Apple-Targets Initially, I thought I'd have to write entire modules from scratch, but expo-apple-targets provided a bridge between Expo’s JavaScript environment and iOS’s native features. This tool leverages the Expo Modules API to write native Swift code and expose it to JavaScript, making the process much more manageable. Key Steps in Development Setting Up the Project Avoid Constant Updates: Initially, I planned to update the Live Activity every second, but this approach led to significant system load and battery drain. A Reddit thread clued me in to using SwiftUI’s Text(timerInterval:) view, which handles updates efficiently. Define LiveActivityAttributes: This struct holds the static data (e.g., activityName, activityIcon) and dynamic content state (e.g., startedAt, pausedAt). The struct’s helper methods ensure the timer runs smoothly and efficiently. Start the Live Activity: The startActivity function initializes a new Live Activity. It sets the startedAt time and ensures the app handles state transitions gracefully. Pause the Timer: The performPause function updates the Live Activity’s state when the user pauses the timer. It validates the current state to prevent errors and uses intents to communicate with the JavaScript layer. The Visual Heart of the Live Activity Lock Screen View The LockScreenLiveActivityView is designed to be visually appealing and functional. It displays the activity name and icon, along with a timer that either ticks or shows static elapsed time. Buttons for pausing, resuming, and completing the activity provide user interactions without opening the app. Dynamic Island Views The DynamicIsland view adapts to different display modes: - Expanded Mode: Shows the activity name, icon, and a large, precise timer. Buttons for pausing, resuming, and completing the activity are prominently displayed. - Compact Mode: Displays a smaller icon and truncated name, along with a less detailed timer. - Minimal Mode: Shows only a small icon, indicating the timer is still active. _shared Folder: Seamless Integration The _shared folder in expo-apple-targets is crucial for linking essential code to both the main app target and the Live Activity widget. This ensures that both components share the same state (e.g., startedAt, pausedAt) without manual configuration, maintaining consistency and reducing errors. Handling User Interactions Launching the App from the Widget The CompleteIntent allows users to tap a checkmark button on the widget to open the app and complete their timer. This intent posts a notification that is caught by the native module, triggering an onWidgetCompleteActivity event to JavaScript. This seamless interaction is key to a user-friendly experience. Pausing the Timer with Intent The PauseIntent is similarly straightforward but powerful. It posts a notification when the user taps the pause button on the widget, updating the Live Activity’s state and sending an onLiveActivityUpdate event to JavaScript. Events and JavaScript Synchronization Two primary events keep the React Native app in sync with the Live Activity: - onWidgetCompleteActivity:-fired when the user completes the activity, this event provides the activity ID and elapsed time, allowing JavaScript to update the app’s UI or log the workout’s completion. - onLiveActivityUpdate: fired on state changes (e.g., pause, resume), this event sends the current state, elapsed time, and activity ID to JavaScript, ensuring the app’s timer UI mirrors the widget’s status. Why This Feature Matters This Live Activity timer enhances the app’s functionality and user experience by providing real-time, glanceable information on the Lock Screen and Dynamic Island. expo-apple-targets and the Expo Modules API were instrumental in achieving this integration, simplifying the process and ensuring a maintainable codebase. Live Activities are a powerful tool for making apps feel more connected and dynamic, and this project demonstrates how they can be implemented effectively in an Expo environment. For developers interested in diving deeper, the full source code is available on GitHub at the provided link. This project serves as a practical example of how to leverage native iOS features in a React Native app, opening up new possibilities for user engagement and app functionality.
