-
Notifications
You must be signed in to change notification settings - Fork 50
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
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!
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested