无法使用cordova-plugin-x-socialsharing共享文件

时间:2017-08-08 13:37:04

标签: cordova ionic-framework ionic2 ionic3 ionic-native

我正在尝试使用cordova-plugin-x-socialsharing共享备份文件*.bkp 在我的离子项目中,使用任何文件管理器都是成功共享文件。但内部使用myapp失败..

我已经从SocialSharing-PhoneGap-Plugin

尝试此代码
import { File, SocialSharing } from 'ionic-native';

export class Filemanager {
        constructor(
        public _BackPress: BackPress,
        public toastCtrl: ToastController,
        public viewCtrl: ViewController,
        public alertCtrl: AlertController,
        public navCtrl: NavController,
        public navParams: NavParams) {

                   let path ="file:///storage/emulated/0/Android/sample/Bocaue_Caingin_-08082017082411.bkp"
                   SocialSharing.share(null,null, path ).then(data => {

                    }).catch(data => {
                      console.log('catch> error ',data)
                      let toast = this.toastCtrl.create({
                        message: 'Share File Failed!',
                        duration: 2500
                      });
                      toast.present();

                    });

      }
}
//the console log result
//catch> error  false

我的目标是通过shareitapp或作为附件的信使共享文件

继承我的Package.json

{
    "name": "ionic-hello-world",
    "version": "0.0.0",
    "author": "Ionic Framework",
    "homepage": "http://ionicframework.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "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/core": "3.10.2",
        "@ionic-native/sqlite": "^3.12.1",
        "@ionic/storage": "2.0.1",  
        "angular2-moment": "^1.1.0", 
        "cordova-android": "^6.2.3",
        "cordova-plugin-compat": "1.1.0",
        "cordova-plugin-console": "^1.0.7",
        "cordova-plugin-device": "^1.1.6",
        "cordova-plugin-file": "^4.3.3",
        "cordova-plugin-splashscreen": "^4.0.3", 
        "cordova-plugin-statusbar": "^2.2.3",
        "cordova-plugin-whitelist": "^1.3.2",
        "cordova-plugin-x-socialsharing": "^5.1.8",
        "cordova-sqlite-storage": "^2.0.4",  
        "ionic-angular": "3.5.2",
        "ionic-native": "2.9.0",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",       
        "rxjs": "5.4.0",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.12"
    },
    "devDependencies": {
        "@ionic/app-scripts": "2.0.2",
        "typescript": "2.3.4"
    },
    "cordovaPlugins": [
        "cordova-plugin-statusbar",
        "cordova-plugin-device",
        "cordova-plugin-whitelist",
        "cordova-plugin-console",
        "ionic-plugin-keyboard",
        "cordova-plugin-splashscreen"
    ],
    "cordovaPlatforms": [],
    "description": "project_name: An Ionic project",
    "cordova": {
        "plugins": {
            "cordova-plugin-console": {},
            "cordova-plugin-device": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {},
            "cordova-sqlite-storage": {},
            "cordova-plugin-file": {},
            "cordova-plugin-x-socialsharing": {}, 
        },
        "platforms": [
            "android"
        ]
    }
}

1 个答案:

答案 0 :(得分:0)

我可以看到您的实施有两个问题。

  1. 您正在使用非常旧的本机依赖项。您必须将其更新为最新的"@ionic-native/core": "3.13.1",Offical package.json文件。

  2. 之后,您可以使用Ionic native插件轻松实现它,如下所示。

  3. 这是official doc

    import { SocialSharing } from '@ionic-native/social-sharing';
    
    constructor(private socialSharing: SocialSharing) { }
    
    // Check if sharing via email is supported
    this.socialSharing.canShareViaEmail().then(() => {
      // Sharing via email is possible
    }).catch(() => {
      // Sharing via email is not possible
    });