2016-05-03 10 views
1

私たちはIonicのiOSプロジェクトに取り組んでいます。我々は、(最初​​にアプリに入るときに)ionicview enterで発射するcordovaスクリーンショットプラグインをし、スクリーンショットを送信するためにcordovaファイル転送を使用します。

最初にビューに入るときに、以下のコードは機能しません。しかし、ビューを離れて戻ってくると、スクリーンショットが送信されます。

ただし、最初のlogActionは、2回目のlogActionではこのビューに初めて入ります。このビューを2回目に入力すると、両方のlogActionsが起動されます。

これは私が言及していたコードの一部です:

$scope.$on('$ionicView.enter', function() { 
    $scope.logAction({ 
     "Message": "Login screen succesfully entered", 
     "Succeeded": true, 
     "transaction": 1, 
     "Category": "Info", 
     "Device": 0, 
    }) 
    $cordovaScreenshot.capture().then(function(filepath){ 
    $scope.logAction({ 
     "Message": filepath, 
     "Succeeded": true, 
     "transaction": 1, 
     "Category": "Info", 
     "Device": 0, 
    }) 
    $cordovaScreenshot.send(filepath); 
    }); 
}); 

これはcordovaScreenshotファイルです

angular.module('testScreenshots.services', []) 
.service('$cordovaScreenshot', ['$q',function ($q) { 
    return { 
     fileURL: "", 
     capture: function (filename, extension, quality) { 
      var randomNumber = Math.random(); 
      console.log("" + randomNumber); 
      filename = "testPicture" + randomNumber.toString(); 
      extension = extension || 'jpg'; 
      quality = quality || '100'; 

      var defer = $q.defer(); 


      navigator.screenshot.save(function (error, res){ 
       if (error) { 
        console.error(error); 
        defer.reject(error); 
       } else { 
        console.log('screenshot saved in: ', res.filePath); 
        this.fileURL = "file://" + res.filePath; 
        defer.resolve(res.filePath); 
        console.log("inside the save function: "+this.fileURL); 
       } 
      }, extension, quality, filename); 

      return defer.promise; 
     }, 


     send: function(filepath){ 

      var win = function (r) { 
      console.log("Code = " + r.responseCode); 
      console.log("Response = " + r.response); 
      console.log("Sent = " + r.bytesSent); 
      } 

      var fail = function (error) { 
      alert("An error has occurred: Code = " + error.code); 
      console.log("upload error source " + error.source); 
      console.log("upload error target " + error.target); 
      } 

      var options = new FileUploadOptions(); 
      options.fileKey = "file"; 
      options.fileName = filepath.substr(filepath.lastIndexOf('/') + 1); 
      options.mimeType = "multipart/form-data"; 
      options.chunkedMode = false; 
      options.headers = { 
      Connection: "close" 
      }; 

      var ft = new FileTransfer(); 
      ft.upload(filepath, encodeURI("http://192.168.6.165:8080//api/uploadpicture"), win, fail, options); 
     } 
    }; 
}]) 

答えて

0

我々はMacで使うのiOSシミュレータは、この問題を持っていました。デバイス上で実行しようとした後、問題はもはや私たちに影響を与えませんでした。

この問題は、iOSシミュレータの使用に関連しているようです。

関連する問題