dpogue commented on code in PR #942:
URL: 
https://github.com/apache/cordova-plugin-camera/pull/942#discussion_r2709590576


##########
src/ios/CDVCamera.m:
##########
@@ -362,20 +347,35 @@ - (void)picker:(PHPickerViewController*)picker 
didFinishPicking:(NSArray<PHPicke
         
         // Check if it's a video
         if ([pickerResult.itemProvider 
hasItemConformingToTypeIdentifier:UTTypeMovie.identifier]) {
-            [pickerResult.itemProvider 
loadFileRepresentationForTypeIdentifier:UTTypeMovie.identifier 
completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
+            // Writes a copy of the data to a temporary file. This file will 
be deleted
+            // when the completion handler returns. The program should copy or 
move the file within the completion handler.
+            [pickerResult.itemProvider 
loadFileRepresentationForTypeIdentifier:UTTypeMovie.identifier
+                                                             
completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {

Review Comment:
   It might be worth adding a note here for future developers that the 
completionHandler is invoked on a thread, because the NSItemProvider 
documentation does not mention that in the docs for 
`loadFileRepresentationForTypeIdentifier:completionHandler:` (but does mention 
it in passing on the NSItemProvider class summary)



##########
src/ios/CDVCamera.m:
##########
@@ -362,20 +347,35 @@ - (void)picker:(PHPickerViewController*)picker 
didFinishPicking:(NSArray<PHPicke
         
         // Check if it's a video
         if ([pickerResult.itemProvider 
hasItemConformingToTypeIdentifier:UTTypeMovie.identifier]) {
-            [pickerResult.itemProvider 
loadFileRepresentationForTypeIdentifier:UTTypeMovie.identifier 
completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
+            // Writes a copy of the data to a temporary file. This file will 
be deleted
+            // when the completion handler returns. The program should copy or 
move the file within the completion handler.
+            [pickerResult.itemProvider 
loadFileRepresentationForTypeIdentifier:UTTypeMovie.identifier
+                                                             
completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
                 if (error) {
-                    CDVPluginResult* result = [CDVPluginResult 
resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error 
localizedDescription]];
+                    NSLog(@"CDVCamera: Failed to load video: %@", [error 
localizedDescription]);
+                    CDVPluginResult* result = [CDVPluginResult 
resultWithStatus:CDVCommandStatus_IO_EXCEPTION
+                                                                
messageAsString:[NSString stringWithFormat:@"Failed to load video: %@", [error 
localizedDescription]]];
                     [weakSelf.commandDelegate sendPluginResult:result 
callbackId:callbackId];
                     weakSelf.hasPendingOperation = NO;
                     return;
                 }
                 
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    NSString* videoPath = [weakSelf createTmpVideo:[url path]];
-                    CDVPluginResult* result = [CDVPluginResult 
resultWithStatus:CDVCommandStatus_OK messageAsString:videoPath];
-                    [weakSelf.commandDelegate sendPluginResult:result 
callbackId:callbackId];
-                    weakSelf.hasPendingOperation = NO;
-                });
+                // The temporary file provided by PHPickerViewController is 
deleted when the completion
+                // handler exits. The file has to be copied in this thread, 
otherwise it will be gone.
+                NSString* videoPath = [weakSelf createTmpVideo:[url path]];
+                
+                // Send Cordova plugin result back, which must be done on the 
main thread

Review Comment:
   This comment is not accurate, since this isn't happening on the main thread?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to