Ionic Cordova原生插件不适用于IOS

时间:2018-05-10 10:41:48

标签: ios iphone cordova ionic-framework

我正在开发一款在Android和IOS中使用的Ionic应用程序。在我的应用程序中,我使用以下插件使用打印,共享和条形码扫描仪功能

  1. cordova-plugin-x-socialsharing 5.4.0 for" SocialSharing"
  2. cordova-plugin-printer 0.7.3 for" Printer"
  3. cordova-plugin-barcodescanner 0.7.4 for" BarcodeScanner"
  4. 这些插件适用于Android,但是当我使用IOS进行测试时,我遇到了以下所有插件的相同问题:

      

    当我点击iPhone中的打印按钮时,没有任何反应

         

    但是当我按下主页按钮并重新打开应用程序然后打印弹出窗口时   自动。同样的问题我也面对其他插件。

         

    我认为它是IOS的背景功能问题。

    我来自Android背景,所以我无法理解为什么IOS会发生这种情况,我坚持使用它。

    这是我的代码部分:

    打印:

    print() {
      this.printer.isAvailable().then((onSuccess=>{}), onerror=>{});
      this.printer.check().then((onSuccess=>{}), onerror=>{});
      let options: PrintOptions = {
        name: 'MyDocument',
        duplex: true,
        landscape: true,
        grayscale: true
      };
      let printData = this.printContent(); 
      setTimeout(() => {
        this.platform.ready().then(success => {
          this.printer.print(printData).then(function() {},
            function() { alert("Error while printing!"); });
        }, error=> { alert('Platform Not Ready'+error); });
      }, 100);
    }
    

    分享

    savebase64AsPDF(folderpath,filename,content,contentType) {
      // Convert the base64 string in a Blob
      var DataBlob = this.b64toBlob(content,contentType,12);
      console.log("Starting to write the file :3");
      window['resolveLocalFileSystemURL'](folderpath, function(dir) {
        console.log("Access to the directory granted succesfully");
        this.file = dir.getFile(filename, {create:true}, function(file) {
          console.log("File created succesfully.");
          file.createWriter(function(fileWriter) {
            console.log("Writing content to file");
            fileWriter.write(DataBlob);
          }, function(){
            alert('Unable to save file in path '+ folderpath);
          });
        });
      });
      //this.downloadFile(DataBlob);
      this.socialSharing.share("",""+this.record.orderNo+" Sale Order",folderpath+"/"+filename,null).then(() => { }).catch((error) => { alert(error); });
    }
    

    扫描

    cordova.plugins.barcodeScanner.scan(
          function (result) {
              alert("We got a barcode\n" +
                    "Result: " + result.text + "\n" +
                    "Format: " + result.format + "\n" +
                    "Cancelled: " + result.cancelled);
          },
          function (error) {
              alert("Scanning failed: " + error);
          }
       );
    

    的package.json

    {
      "name": "AppName",
      "version": "1.0.3",
      "author": "Ionic Framework",
      "homepage": "http://ionicframework.com/",
      "private": true,
      "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build --prod",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
      },
      "config": {
        "ionic_source_map": "source_map"
      },
      "dependencies": {
        "@angular/common": "4.1.3",
        "@angular/compiler": "4.1.3",
        "@angular/compiler-cli": "4.1.3",
        "@angular/core": "4.1.3",
        "@angular/forms": "4.1.3",
        "@angular/http": "4.1.3",
        "@angular/platform-browser": "4.1.3",
        "@angular/platform-browser-dynamic": "4.1.3",
        "@ionic-native/app-preferences": "4.7.0",
        "@ionic-native/barcode-scanner": "^4.7.0",
        "@ionic-native/core": "4.7.0",
        "@ionic-native/file": "^4.7.0",
        "@ionic-native/printer": "4.7.0",
        "@ionic-native/social-sharing": "^4.7.0",
        "@ionic-native/splash-screen": "4.7.0",
        "@ionic-native/sqlite": "4.7.0",
        "@ionic-native/status-bar": "4.7.0",
        "@ionic/pro": "^1.0.16",
        "@ionic/storage": "^2.1.3",
        "amazon-cognito-identity-js": "^1.26.0",
        "angular2-signaturepad": "^2.6.1",
        "aws-sdk": "^2.156.0",
        "cordova-browser": "~5.0.3",
        "cordova-pdf-generator": "^2.0.0",
        "cordova-plugin-add-swift-support": "^1.7.1",
        "cordova-plugin-android-permissions": "^1.0.0",
        "cordova-plugin-barcodescanner": "^0.7.4",
        "cordova-plugin-certificates": "^0.6.4",
        "cordova-plugin-compat": "^1.2.0",
        "cordova-plugin-device": "^1.1.7",
        "cordova-plugin-file": "^6.0.1",
        "cordova-plugin-http": "^1.2.0",
        "cordova-plugin-ionic": "^2.0.4",
        "cordova-plugin-printer": "^0.7.3",
        "cordova-plugin-splashscreen": "^4.0.0",
        "cordova-plugin-sslcertificatechecker": "^5.1.0",
        "cordova-plugin-statusbar": "^2.4.1",
        "cordova-plugin-whitelist": "^1.3.3",
        "cordova-plugin-x-socialsharing": "^5.4.0",
        "es6-promise-plugin": "^4.2.2",
        "ionic-angular": "3.9.2",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "phonegap-plugin-barcodescanner": "^7.1.2",
        "rxjs": "^5.4.2",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.12"
      },
      "devDependencies": {
        "@ionic/app-scripts": "3.1.9",
        "@types/node": "^8.5.1",
        "json-loader": "^0.5.7",
        "typescript": "2.3.4",
        "webpack": "^3.8.1"
      },
      "description": "An Ionic project",
      "cordova": {
        "plugins": {
          "cordova-plugin-device": {},
          "cordova-plugin-statusbar": {},
          "cordova-plugin-android-permissions": {},
          "cordova-plugin-sslcertificatechecker": {},
          "cordova-plugin-certificates": {},
          "cordova-plugin-http": {},
          "cordova-plugin-whitelist": {},
          "cordova-plugin-file": {},
          "cordova-pdf-generator": {},
          "cordova-plugin-splashscreen": {},
          "cordova-plugin-ionic": {
            "APP_ID": "e363211c",
            "CHANNEL_NAME": "Production",
            "UPDATE_METHOD": "background",
            "UPDATE_API": "https://api.ionicjs.com",
            "MAX_STORE": "2"
          },
          "ionic-plugin-keyboard": {},
          "cordova-plugin-x-socialsharing": {},
          "cordova-plugin-printer": {},
          "cordova-plugin-barcodescanner": {}
        },
        "platforms": [
          "browser"
        ]
      }
    }
    

0 个答案:

没有答案