@@ -26,25 +26,38 @@ + (nullable NSURL *)compileModelAtURL:(NSURL *)modelURL
26
26
#else
27
27
__block NSError *localError = nil ;
28
28
__block NSURL *result = nil ;
29
-
30
- dispatch_semaphore_t sema = dispatch_semaphore_create (0 );
31
- [MLModel compileModelAtURL: modelURL completionHandler: ^(NSURL * _Nullable tempURL, NSError * _Nullable compilationError) {
32
- result = [tempURL copy ];
33
- localError = compilationError;
34
- dispatch_semaphore_signal (sema);
35
- }];
36
-
37
- long status = dispatch_semaphore_wait (sema, dispatch_time (DISPATCH_TIME_NOW, (int64_t )(maxWaitTimeInSeconds * NSEC_PER_SEC)));
38
- if (status != 0 ) {
29
+
30
+ if (@available (iOS 16 , macOS 13 , watchOS 9 , tvOS 16 , *)) {
31
+ dispatch_semaphore_t sema = dispatch_semaphore_create (0 );
32
+ [MLModel compileModelAtURL: modelURL completionHandler: ^(NSURL * _Nullable tempURL, NSError * _Nullable compilationError) {
33
+ result = [tempURL copy ];
34
+ localError = compilationError;
35
+ dispatch_semaphore_signal (sema);
36
+ }];
37
+
38
+ long status = dispatch_semaphore_wait (sema, dispatch_time (DISPATCH_TIME_NOW, (int64_t )(maxWaitTimeInSeconds * NSEC_PER_SEC)));
39
+ if (status != 0 ) {
40
+ ETCoreMLLogErrorAndSetNSError (error,
41
+ ETCoreMLErrorCompilationFailed,
42
+ " %@: Failed to compile model in %f seconds." ,
43
+ NSStringFromClass (ETCoreMLModelCompiler.class ),
44
+ maxWaitTimeInSeconds);
45
+ return nil ;
46
+ }
47
+ } else {
48
+ result = [MLModel compileModelAtURL: modelURL error: &localError];
49
+ }
50
+
51
+ if (localError) {
39
52
ETCoreMLLogErrorAndSetNSError (error,
40
- ETCoreMLErrorCompilationFailed,
41
- " %@: Failed to compile model in %f seconds. " ,
42
- NSStringFromClass (ETCoreMLModelCompiler.class ),
43
- maxWaitTimeInSeconds );
53
+ ETCoreMLErrorCompilationFailed,
54
+ " %@: Failed to compile model, error: %@ " ,
55
+ NSStringFromClass (ETCoreMLModelCompiler.class ),
56
+ localError );
44
57
return nil ;
58
+ } else {
59
+ return result;
45
60
}
46
-
47
- return result;
48
61
#endif
49
62
}
50
63
0 commit comments