react-native-siri-shortcut: Not working with Scenes
I’ve had to convert my AppDelegate to Swift, because my radio station app uses react-native-carplay, which now requires use of iOS Scenes which in turns requires a Swift AppDelegate.
Everything is working fine except for react-native-siri-shortcut (it was working fine before this).
I can add a shortcut still, but when I say “Hey Siri, play [name of station]” - the app opens, but getInitialShortcut
returns null. Same goes for using addShortcutListener
while the app is open - the event is never triggered.
Here’s what AppDelegate.swift looks like. I used Swiftify to convert react-native-siri-shortcut’s bit (and others) to Swift.
import UIKit
import CarPlay
import React
...
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
var bridge: RCTBridge?;
var rootView: RCTRootView?;
static var shared: AppDelegate { return UIApplication.shared.delegate as! AppDelegate }
func sourceURL(for bridge: RCTBridge!) -> URL! {
#if DEBUG
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index");
#else
return Bundle.main.url(forResource:"main", withExtension:"jsbundle")
#endif
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
self.bridge = RCTBridge(delegate: self, launchOptions: launchOptions)
let rootView = RCTRootView(bridge: self.bridge!, moduleName: "aiirmobile", initialProperties: nil)
if #available(iOS 13.0, *) {
rootView.backgroundColor = UIColor.systemBackground
} else {
rootView.backgroundColor = UIColor.white
}
self.rootView = rootView
...
return true
}
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
if (connectingSceneSession.role == UISceneSession.Role.carTemplateApplication) {
let scene = UISceneConfiguration(name: "CarPlay", sessionRole: connectingSceneSession.role)
scene.delegateClass = CarSceneDelegate.self
return scene
} else {
let scene = UISceneConfiguration(name: "Phone", sessionRole: connectingSceneSession.role)
scene.delegateClass = PhoneSceneDelegate.self
return scene
}
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
...
// Added for react-native-siri-shortcut
func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
return RNSSSiriShortcuts.application(application, continue: userActivity, restorationHandler: restorationHandler)
}
}
Then in myapp-Bridging-Header.h I have:
#import <React/RCTBridge.h>
#import <React/RCTRootView.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTAppSetupUtils.h>
#import <RNSiriShortcuts/RNSiriShortcuts.h>
#import "RNCarPlay.h"
Any thoughts or guidance would be greatly appreciated!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 31 (31 by maintainers)
Yeah, that seems like a bug on the OS or API side tbh. Btw, I forgot to add the new example project’s folder to .npmignore, so the size of the library in versions 3.2.0…3.2.1 is too big.
You should install version 3.2.2 which fixes this issue, sorry about that
Oh that’s interesting, thanks. I would have had no idea how to do that, or whether it’s a good idea. Thanks!
Here we are: https://github.com/Gustash/react-native-siri-shortcut/pull/105 You can see the affected files in the example project, here: https://github.com/Gustash/react-native-siri-shortcut/pull/105/commits/e415429e44bcc795c0587e9e0826be224822fce3
Amazing, thank you for your hard work. A new example project for scenes is perfectly fine, just note on the PR which files in the example project are relevant to these changes.
Whenever you can, submit a PR with these fixes please 😄
Thanks for leaving it open, I will definitely give an update once I land on the reason.