0

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:
https://developer.apple.com/documentation/widgetkit/linking-to-specific-app-scenes-from-your-widget-or-live-activity

2 Answers 2

1

Normally the default behavior is that it will open the app after your code runs but if that is not happening then try setting the openAppWhenRun parameter to true:

@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.") static var openAppWhenRun: Bool = true 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() } } 
Sign up to request clarification or add additional context in comments.

Comments

0

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.

https://developer.apple.com/documentation/widgetkit/linking-to-specific-app-scenes-from-your-widget-or-live-activity

1 Comment

Would this work if with React Native Views? Any chance you can provide an example?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.