@@ -745,8 +745,9 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
745
745
cameraCaptureUI . photoSettings . maxResolution = maxRes ;
746
746
747
747
var cameraPicture ;
748
- var savePhotoOnFocus = function ( ) {
749
-
748
+
749
+ // define focus handler for windows phone 10.0
750
+ var savePhotoOnFocus = function ( ) {
750
751
window . removeEventListener ( "focus" , savePhotoOnFocus ) ;
751
752
// call only when the app is in focus again
752
753
savePhoto ( cameraPicture , {
@@ -758,16 +759,31 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
758
759
} , successCallback , errorCallback ) ;
759
760
} ;
760
761
761
- // add and delete focus eventHandler to capture the focus back from cameraUI to app
762
- window . addEventListener ( "focus" , savePhotoOnFocus ) ;
763
- cameraCaptureUI . captureFileAsync ( WMCapture . CameraCaptureUIMode . photo ) . done ( function ( picture ) {
762
+ // if windows phone 10, add and delete focus eventHandler to capture the focus back from cameraUI to app
763
+ if ( navigator . appVersion . indexOf ( 'Windows Phone 10.0' ) >= 0 ) {
764
+ window . addEventListener ( "focus" , savePhotoOnFocus ) ;
765
+ }
766
+
767
+ cameraCaptureUI . captureFileAsync ( WMCapture . CameraCaptureUIMode . photo ) . done ( function ( picture ) {
764
768
if ( ! picture ) {
765
769
errorCallback ( "User didn't capture a photo." ) ;
770
+ // Remove the focus handler if present
766
771
window . removeEventListener ( "focus" , savePhotoOnFocus ) ;
767
772
return ;
768
773
}
769
774
cameraPicture = picture ;
770
- } , function ( ) {
775
+
776
+ // If not windows 10, call savePhoto() now. If windows 10, wait for the app to be in focus again
777
+ if ( navigator . appVersion . indexOf ( 'Windows Phone 10.0' ) < 0 ) {
778
+ savePhoto ( cameraPicture , {
779
+ destinationType : destinationType ,
780
+ targetHeight : targetHeight ,
781
+ targetWidth : targetWidth ,
782
+ encodingType : encodingType ,
783
+ saveToPhotoAlbum : saveToPhotoAlbum
784
+ } , successCallback , errorCallback ) ;
785
+ }
786
+ } , function ( ) {
771
787
errorCallback ( "Fail to capture a photo." ) ;
772
788
window . removeEventListener ( "focus" , savePhotoOnFocus ) ;
773
789
} ) ;
0 commit comments