Skip to content

Commit 9142ce0

Browse files
committed
feat(ios): add getConnectionStatus to determine if phone is also connected
1 parent 3213da4 commit 9142ce0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

packages/react-native-carplay/ios/RNCarPlay.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,36 @@ - (void)updateListRowItemImageWithURL:(CPListImageRowItem *)item imgUrl:(NSStrin
216216
}
217217
}
218218

219+
RCT_REMAP_METHOD(getConnectionStatus,
220+
resolver:(RCTPromiseResolveBlock)resolve
221+
rejecter:(RCTPromiseRejectBlock)reject)
222+
{
223+
// Check for CarPlay scene
224+
BOOL carplayConnected = NO;
225+
for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
226+
if ([scene isKindOfClass:[CPTemplateApplicationScene class]]) {
227+
carplayConnected = YES;
228+
break;
229+
}
230+
}
231+
232+
// Check for phone (active foreground window scene)
233+
BOOL phoneConnected = NO;
234+
for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
235+
if ([scene isKindOfClass:[UIWindowScene class]] &&
236+
scene.activationState == UISceneActivationStateForegroundActive) {
237+
phoneConnected = YES;
238+
break;
239+
}
240+
}
241+
242+
resolve(@{
243+
@"carplay": @(carplayConnected),
244+
@"phone": @(phoneConnected)
245+
});
246+
}
247+
248+
219249
RCT_EXPORT_METHOD(createTemplate:(NSString *)templateId config:(NSDictionary*)config callback:(id)callback) {
220250
// Get the shared instance of the RNCPStore class
221251
RNCPStore *store = [RNCPStore sharedManager];

packages/react-native-carplay/src/CarPlay.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { RoutePreviewNavigationTemplate } from './templates/android/RoutePreview
3333

3434
export interface InternalCarPlay extends NativeModule {
3535
checkForConnection(): void;
36+
getConnectionStatus(): Promise<{carplay: boolean, phone: boolean}>;
3637
setRootTemplate(templateId: string, animated: boolean): void;
3738
pushTemplate(templateId: string, animated: boolean): void;
3839
popToTemplate(templateId: string, animated: boolean): void;

0 commit comments

Comments
 (0)