Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live Activities #595

Merged
merged 7 commits into from
Sep 30, 2024
Merged

Live Activities #595

merged 7 commits into from
Sep 30, 2024

Conversation

rlepinski
Copy link
Collaborator

@rlepinski rlepinski commented Sep 27, 2024

Support for managing Live Activities from React. There is still some native code to wire up the types since I have not found a way (even possible?) to infer the types from a string on swift.

TODO:

  • Create
  • List
  • Update
  • End
  • Events
  • Fix android
  • Docs
  • Test restore

Usage

Using the AirshipPluginExtender, configure them:

import Foundation
import AirshipKit
import AirshipFrameworkProxy
import ActivityKit

@objc(AirshipPluginExtender)
public class AirshipPluginExtender: NSObject, AirshipPluginExtenderProtocol {

    public static func onAirshipReady() {
        if #available(iOS 16.1, *) {
            // Will throw if called more than once
            try? LiveActivityManager.shared.setup { configurator in

                // Call per widget type
                await configurator.register(
                    forType: Activity<ExampleWidgetsAttributes>.self,
                ) { attributes in
                    // Track this property as the Airship name for updates. This supports
                    // both local activities being started and starting from a Push.
                    attributes.name
                }
            }
        }
    }
}

Then on the React side:

// Create
Airship.iOS.liveActivityManager.create({
  attributesType: 'ExampleWidgetsAttributes',
  content: {
    state: {
      emoji: '🙌',
    },
    relevanceScore: 0.0,
  },
  attributes: {
    name: 'some-unique-name',
  },
});

// List
Airship.iOS.liveActivityManager.list({
  attributesType: 'ExampleWidgetsAttributes',
});

// Update
Airship.iOS.liveActivityManager.update({
  activityId: activityId,
  attributesType: 'Example',
  content: {
    state: {
      emoji: '🙌🙌',
    },
    relevanceScore: 0.0,
  },
});

// End
Airship.iOS.liveActivityManager.end({
  activityId: activityId,
  attributesType: 'ExampleWidgetsAttributes',
});


// Listen
Airship.addListener(EventType.IOSLiveActivitiesUpdated, (event) => {
    console.log('Live Activities updated:', JSON.stringify(event));
});

@rlepinski
Copy link
Collaborator Author

@robwalkerco @gkueny You two are the only ones that have had open issues about Live Activities, so I was wondering if you had any input on the APIs we are going to expose to manage this? I want to have this released in the coming week, so if you have input please let me know ASAP :)

@gkueny
Copy link

gkueny commented Sep 30, 2024

Hi @rlepinski , on my end we start/update/end our LiveActivity by push notification with airship API.

We do not manage them on the JS side.
For what I see, your APIs seems fine to me

@rlepinski rlepinski marked this pull request as ready for review September 30, 2024 16:55
@rlepinski rlepinski merged commit 3a0ca80 into main Sep 30, 2024
1 check passed
@rlepinski rlepinski deleted the live-activities branch October 26, 2024 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants