简体   繁体   English

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

[英]Failed to share file using cordova-plugin-x-socialsharing

I am trying to share a backup file *.bkp using cordova-plugin-x-socialsharing in my ionic project , using any file manager is success sharing the file. 我试图在我的离子项目中使用cordova-plugin-x-socialsharing共享备份文件*.bkp ,使用任何文件管理器都可以成功共享文件。 but inside using myapp failed.. 但是在内部使用myapp失败。

I already try this code from SocialSharing-PhoneGap-Plugin 我已经从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

My objective is to share to file via shareitapp, or on messenger as an attachment 我的目标是通过shareitapp共享文件,或在Messenger上作为附件共享

Heres my Package.json 这是我的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"
        ]
    }
}

I can see 2 issues with your implementation. 我可以看到您的实施有2个问题。

  1. You're using very OLD native dependency.You must update it to latest "@ionic-native/core": "3.13.1", . 您正在使用非常老的本机依赖性。必须将其更新为最新的"@ionic-native/core": "3.13.1", Offical package.json file. 官方的 package.json文件。

  2. After that, you can easily implement it using the Ionic native plugin as shown below. 之后,您可以使用Ionic native插件轻松实现它,如下所示。

Here is the 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
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法安装cordova-plugin-x-socialsharing - Unable to installed cordova-plugin-x-socialsharing 为什么我不能使用 cordova-plugin-x-socialsharing 在 MMS cordova ios 中共享消息和图像 - Why can't I share both message and image in MMS cordova ios using cordova-plugin-x-socialsharing 大文件的cordova-plugin-x-socialsharing崩溃 - cordova-plugin-x-socialsharing crashes with big files 更新 cordova-plugin-x-socialsharing 插件后,Ionic Android 构建错误 - Ionic Android build error after updating cordova-plugin-x-socialsharing plugin 使用带有链接的 Cordova SocialSharing 插件将图片分享到 Facebook - Share image to Facebook using Cordova SocialSharing plugin with link attached 无法使用Android上的Cordova Socialsharing插件在Facebook上共享自定义文本 - Cannot share custom text on facebook with cordova socialsharing plugin on android Ionic Cordova Social Share 插件 - 无法读取未定义的属性“socialsharing” - Ionic Cordova Social Share plugin - cannot read property 'socialsharing' of undefined Phonegap / Cordova:社交共享插件不起作用 - Phonegap / Cordova: socialsharing plugin not working 使用Wordpress JSON的SocialSharing Cordova - SocialSharing Cordova using Wordpress JSON Cordova SocialSharing插件-Facebook回调错误 - Cordova SocialSharing Plugin - Facebook Callback Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM