I’m developing an iOS app with CarPlay support, and I’m trying to open the default phone app scene from the CarPlay scene. This needs to work on all iOS devices, including those that do not support multiple scenes (e.g., older iOS versions or devices that do not have multiple windows).
Scenario:
• The default configuration scene is the phone app, and the CarPlay scene is a separate one.
• When interacting with the CarPlay interface, I want to programmatically switch or launch the phone app scene.
I’ve found resources on managing multiple scenes on devices that support it, but not much about how to handle this scenario for devices that only support a single scene.
Could someone guide me on the correct approach to achieve this behavior in Objective-C?
I’d appreciate code examples that work on all iOS devices, including handling cases where multiple scenes aren’t available.
Here’s a rough version of what I’m trying, but I’m unsure how to make this compatible across all devices:
- (void)switchToPhoneAppScene {
if (@available(iOS 13.0, *)) {
NSSet<UIScene *> *connectedScenes = [UIApplication sharedApplication].connectedScenes;
for (UIScene *scene in connectedScenes) {
if ([scene.session.role isEqualToString:UIWindowSceneSessionRoleApplication]) {
// Trying to activate the phone app scene
[UIApplication.sharedApplication requestSceneSessionActivation:scene.session
userActivity:nil
options:nil
errorHandler:nil];
return;
}
}
} else {
// For iOS versions below 13 that do not support multiple scenes
// What should be done here to ensure compatibility?
}
}
What would be the best way to handle scene activation or app switching across all iOS devices, regardless of whether they support multiple scenes?
Thanks in advance!
user26935310 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1