@neoskola/auto-play 0.2.13 → 0.2.15
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.
|
@@ -71,19 +71,19 @@ class AutoPlayInterfaceController: NSObject, CPInterfaceControllerDelegate {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/// Pushes CPNowPlayingTemplate using ObjC @try/@catch to prevent crash from NSException.
|
|
74
|
+
/// The push call is made entirely in Objective-C so NSExceptions never propagate through Swift frames.
|
|
74
75
|
private func pushNowPlayingTemplateSafely(animated: Bool) async -> Bool {
|
|
75
76
|
return await withCheckedContinuation { continuation in
|
|
76
77
|
do {
|
|
77
|
-
try ObjCExceptionCatcher.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
continuation.resume(returning: success)
|
|
78
|
+
try ObjCExceptionCatcher.pushTemplate(
|
|
79
|
+
CPNowPlayingTemplate.shared,
|
|
80
|
+
on: self.interfaceController,
|
|
81
|
+
animated: animated
|
|
82
|
+
) { success, error in
|
|
83
|
+
if let error = error {
|
|
84
|
+
print("[AutoPlay] CPNowPlayingTemplate push completion error: \(error)")
|
|
86
85
|
}
|
|
86
|
+
continuation.resume(returning: success)
|
|
87
87
|
}
|
|
88
88
|
} catch {
|
|
89
89
|
print("[AutoPlay] CPNowPlayingTemplate push threw ObjC exception: \(error.localizedDescription)")
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <CarPlay/CarPlay.h>
|
|
2
3
|
|
|
3
|
-
/// Provides Objective-C @try/@catch exception handling for
|
|
4
|
-
/// Swift's try/catch cannot catch Objective-C NSExceptions
|
|
5
|
-
///
|
|
6
|
-
///
|
|
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)
|
|
10
|
-
|
|
11
|
+
+ (BOOL)pushTemplate:(CPTemplate * _Nonnull)templateToPush
|
|
12
|
+
onInterfaceController:(CPInterfaceController * _Nonnull)interfaceController
|
|
13
|
+
animated:(BOOL)animated
|
|
14
|
+
completion:(void (^ _Nullable)(BOOL success, NSError * _Nullable error))completion
|
|
15
|
+
error:(NSError * _Nullable * _Nullable)error;
|
|
11
16
|
|
|
12
17
|
@end
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
@implementation ObjCExceptionCatcher
|
|
4
4
|
|
|
5
|
-
+ (BOOL)
|
|
5
|
+
+ (BOOL)pushTemplate:(CPTemplate *)templateToPush
|
|
6
|
+
onInterfaceController:(CPInterfaceController *)interfaceController
|
|
7
|
+
animated:(BOOL)animated
|
|
8
|
+
completion:(void (^)(BOOL, NSError *))completion
|
|
9
|
+
error:(NSError **)error {
|
|
6
10
|
@try {
|
|
7
|
-
|
|
11
|
+
[interfaceController pushTemplate:templateToPush animated:animated completion:completion];
|
|
8
12
|
return YES;
|
|
9
13
|
} @catch (NSException *exception) {
|
|
10
|
-
NSLog(@"[ObjCExceptionCatcher] Caught exception: %@ — %@", exception.name, exception.reason);
|
|
14
|
+
NSLog(@"[ObjCExceptionCatcher] Caught exception during pushTemplate: %@ — %@", exception.name, exception.reason);
|
|
11
15
|
if (error) {
|
|
12
16
|
*error = [NSError errorWithDomain:@"ObjCExceptionCatcher"
|
|
13
17
|
code:0
|