Call a Function from iOS Interactive Live Activity into Rn and Also Open the React Native App

Using iOS 17 and React Native, I managed to call a RN function from iOS Live Activities button widget using LiveActivityIntent and NotificationCenter. However, in addition to calling a function into RN, I also would like to open the same React Native app (put it in foreground) (mimic the default Live Activity tap behavior). Can someone please tell me how to do it? If I click the button, it executes the function only, but does not open the app...

@available(iOS 17.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
struct SuperCharge: LiveActivityIntent {
    
    static var title: LocalizedStringResource = "Emoji Ranger SuperCharger"
    static var description = IntentDescription("All heroes get instant 100% health.")
    
    func perform() async throws -> some IntentResult {
        print("calling function from Swift!!!!!")
        
        NotificationCenter.default.post( name: Notification.Name("InvokeEvent"),
                                         object: nil,
                                         userInfo: ["message": "Hello from Widget"]
        )
        return .result()
    }
}

I reviewed the apple docs below, but could not find an answer or example:

1 Answer

The button action for Live Activity is handled similarly to deep linking. We need to provide .widgetURL(URL) to the associated view and handle the URL in application(_:open:) in AppDelegate.

Refer to Apple docs for more information about the linking and navigating to app and app-specific screens.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest