@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
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
|
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)
|
|
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)
|
|
5
|
+
+ (BOOL)pushTemplate:(CPTemplate *)templateToPush
|
|
6
|
+
onInterfaceController:(CPInterfaceController *)interfaceController
|
|
7
|
+
animated:(BOOL)animated
|
|
8
|
+
error:(NSError **)error {
|
|
6
9
|
@try {
|
|
7
|
-
|
|
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
|