Using Social Sharing Cordova Ionic plugin Issue

删除回忆录丶 提交于 2021-02-11 16:56:57

问题


I have been trying to use the Email Composer plugin and the Social Sharing plugin to share a hardcoded subject and typed-by-user body from my Ionic 5 Application. What I want from iOS is to get a share sheet showing all the availalbe email apps i have installed on my device and choose one of them to share the email. At the moment my device is only letting me share the email by using iMail but I want the user to have the opportunity to choose from different email apps such as Gmail, outlook, ect... Also I only have this issue on IOS, Android devices let me choose which email app I want to send with.

This is what I tried and didn't work Social Sharing Plugin try 1:

  PostSuggestion() {
        const formBody = this.suggestion.controls.body.value;
        let Emailsubject: string;
        if (this.currentLanguage === 'en') {
          Emailsubject = 'Suggestion for 123app';
        } else {
          Emailsubject = 'Suġġeriment għal 123App';
        }
        const email = {
          subject: Emailsubject, 
          body: formBody, 
          isHtml: true
        };  
        this.socialSharing.share(formBody, Emailsubject, ['123App@gov.mt']).then(() => {

        }).catch(() => {
          // Error!
        });
      }

Social Sharing Plugin try 2:

   PostSuggestion() {
            const formBody = this.suggestion.controls.body.value;
            let Emailsubject: string;
            if (this.currentLanguage === 'en') {
              Emailsubject = 'Suggestion for 123App';
            } else {
              Emailsubject = 'Suġġeriment għal 123App';
            }
            const email = {
              subject: Emailsubject, 
              body: formBody, 
              isHtml: true
            };  
            this.socialSharing.shareViaEmail(formBody, Emailsubject, ['123App@gov.mt']).then(() => {

            }).catch(() => {
              // Error!
            });
          }

Email Composer Plugin:

PostSuggestion() {
    const formBody = this.suggestion.controls.body.value;
    let Emailsubject: string;
    if (this.currentLanguage === 'en') {
      Emailsubject = 'Suggestion for 123App';
    } else {
      Emailsubject = 'Suġġeriment għal 123App';
    }
    if (this.emailComposer.isAvailable()) {
      if (this.emailComposer.hasPermission()) {
        const email = {
          to: '123@gov.mt', 
          subject: Emailsubject, 
          body: formBody, 
          isHtml: true
        };
        this.emailComposer.open(email).then(() => {
          this.suggestionContents = '';
        });
      } else {
        console.log('No permission granted');
        window.alert('No permission granted'); 
      }
    } else {
      window.alert('User does not appear to have device e-mail account'); 
    }
  }

The first one lets me choose an app but the subject and toSend are always being left empty. The other methods are only giving me the option to use the iMail app iOS has.

Any help please?

来源:https://stackoverflow.com/questions/60613918/using-social-sharing-cordova-ionic-plugin-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!