2017-02-27 91 views
0

我想在我的Ionic 2應用程序中「分享用戶統計信息」。首先,我做了截圖,然後我要與社會共享插件分享..Ionic 2社交分享

這是我的代碼:

public shareStats(): void { 

     // Take a screenshot and get temporary file URI 
     Screenshot.URI(100) 
      .then((img) => { 

       this.platform.ready().then(() => { 

        let message: string = 'Message'; 
        let subject: string = 'Stats'; 
        let file = img; 
        let link = 'https://www.example.com'; 

        SocialSharing.share(message, subject, file, link); 
       }); 

      }, (err) => { 

       let prompt = this.alertCtrl.create({ 
        title: 'Fallo', 
        subTitle: err, 
        buttons: ['Aceptar'] 
       }); 

       prompt.present(); 
       console.log(err); 
      }); 
    } 

嗯,截圖插件看起來做工精細,但我不在將社交分享代碼添加到其中後知道發生了什麼。因爲我的設備沒有打開最終的共享選項窗口。

總之,我需要做截圖並在社交網絡上分享。但我不知道我做錯了什麼,因爲我無法通過作爲cordova插件進行調試,只能在移動設備上運行。

這讓我有點噪音的什麼我送作爲參數:let file = img; 因爲我不知道它包含什麼或什麼樣的數據,這是IMG返回我Screenshot.URI,因爲我不能對它進行調試移動設備。

感謝這麼多提前!

伊萬。

回答

0

我解決了它:

public shareStats(): void { 

     this.platform.ready().then(() => { 
      // Take a screenshot and get temporary file URI 
      Screenshot.URI(100) 
       .then((res) => { 

        var options = { 
         message: this.SHARE_OPTIONS_MESSAGE, 
         subject: '', // fi. for email 
         files: [res.URI], // an array of filenames either locally or remotely 
         url: this.SHARE_OPTIONS_URL, 
         chooserTitle: this.SHARE_OPTIONS_CHOOSER_TITLE // Android only 
        } 

        SocialSharing.shareWithOptions(options) 
         .then(() => { 
          this.showSuccessShareMsg(); 
         }) 
         .catch((err) => { 
          this.showErrorShareMsg(err); 
         }); 

       }, (err) => { 

       }); 
     }); 

    }