@neoskola/auto-play 0.2.14 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,7 +61,7 @@ class AutoPlayInterfaceController: NSObject, CPInterfaceControllerDelegate {
61
61
  return true
62
62
  }
63
63
 
64
- return await pushNowPlayingTemplateSafely(animated: animated)
64
+ return pushNowPlayingTemplateSafely(animated: animated)
65
65
  }
66
66
 
67
67
  return try await interfaceController.pushTemplate(
@@ -71,24 +71,19 @@ class AutoPlayInterfaceController: NSObject, CPInterfaceControllerDelegate {
71
71
  }
72
72
 
73
73
  /// Pushes CPNowPlayingTemplate using ObjC @try/@catch to prevent crash from NSException.
74
- private func pushNowPlayingTemplateSafely(animated: Bool) async -> Bool {
75
- return await withCheckedContinuation { continuation in
76
- do {
77
- try ObjCExceptionCatcher.execute {
78
- self.interfaceController.pushTemplate(
79
- CPNowPlayingTemplate.shared,
80
- animated: animated
81
- ) { success, error in
82
- if let error = error {
83
- print("[AutoPlay] CPNowPlayingTemplate push completion error: \(error)")
84
- }
85
- continuation.resume(returning: success)
86
- }
87
- }
88
- } catch {
89
- print("[AutoPlay] CPNowPlayingTemplate push threw ObjC exception: \(error.localizedDescription)")
90
- continuation.resume(returning: false)
91
- }
74
+ /// The push call is made entirely in Objective-C so NSExceptions never propagate through Swift frames.
75
+ private func pushNowPlayingTemplateSafely(animated: Bool) -> Bool {
76
+ do {
77
+ try ObjCExceptionCatcher.pushTemplate(
78
+ CPNowPlayingTemplate.shared,
79
+ on: self.interfaceController,
80
+ animated: animated
81
+ )
82
+ print("[AutoPlay] CPNowPlayingTemplate pushed successfully")
83
+ return true
84
+ } catch {
85
+ print("[AutoPlay] CPNowPlayingTemplate push threw ObjC exception: \(error.localizedDescription)")
86
+ return false
92
87
  }
93
88
  }
94
89
 
@@ -1,12 +1,16 @@
1
1
  #import <Foundation/Foundation.h>
2
+ #import <CarPlay/CarPlay.h>
2
3
 
3
- /// Provides Objective-C @try/@catch exception handling for Swift code.
4
- /// Swift's try/catch cannot catch Objective-C NSExceptions, which causes
5
- /// crashes when Apple frameworks throw them (e.g., CPInterfaceController.pushTemplate
6
- /// with CPNowPlayingTemplate). This wrapper makes those exceptions catchable.
4
+ /// Provides Objective-C @try/@catch exception handling for CarPlay template pushes.
5
+ /// Swift's try/catch cannot catch Objective-C NSExceptions. When pushTemplate is called
6
+ /// from a Swift closure, the NSException propagates through Swift stack frames and crashes.
7
+ /// This helper performs the pushTemplate call entirely in Objective-C so @try/@catch works.
8
+ API_AVAILABLE(ios(14.0))
7
9
  @interface ObjCExceptionCatcher : NSObject
8
10
 
9
- + (BOOL)executeBlock:(void(NS_NOESCAPE ^_Nonnull)(void))block
11
+ + (BOOL)pushTemplate:(CPTemplate * _Nonnull)templateToPush
12
+ onInterfaceController:(CPInterfaceController * _Nonnull)interfaceController
13
+ animated:(BOOL)animated
10
14
  error:(NSError * _Nullable * _Nullable)error;
11
15
 
12
16
  @end
@@ -2,12 +2,15 @@
2
2
 
3
3
  @implementation ObjCExceptionCatcher
4
4
 
5
- + (BOOL)executeBlock:(void(NS_NOESCAPE ^)(void))block error:(NSError **)error {
5
+ + (BOOL)pushTemplate:(CPTemplate *)templateToPush
6
+ onInterfaceController:(CPInterfaceController *)interfaceController
7
+ animated:(BOOL)animated
8
+ error:(NSError **)error {
6
9
  @try {
7
- block();
10
+ [interfaceController pushTemplate:templateToPush animated:animated completion:nil];
8
11
  return YES;
9
12
  } @catch (NSException *exception) {
10
- NSLog(@"[ObjCExceptionCatcher] Caught exception: %@ — %@", exception.name, exception.reason);
13
+ NSLog(@"[ObjCExceptionCatcher] Caught exception during pushTemplate: %@ — %@", exception.name, exception.reason);
11
14
  if (error) {
12
15
  *error = [NSError errorWithDomain:@"ObjCExceptionCatcher"
13
16
  code:0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neoskola/auto-play",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",