1
votes

enter image description hereI'd have an ionic project that i want to integrate social media sharing on but it seams not working as i keep getting error each time i want to use the class in my constructor. the page will not even load with this on the console.
ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function TypeError: Object(...) is not a function

This what i got from the ionic documentation

  • ionic cordova plugin add cordova-plugin-x-socialsharing
  • npm install --save @ionic-native/social-sharing@4
import { SocialSharing } from "@ionic-native/social-sharing";

constructor(private socialSharing: SocialSharing){}

 compilemsg(index): string {
    var msg = this.post[index].body + "..." + this.post[index].title;
    return msg.concat(" \n Awesome !");
  }

  shareMedia(index) {
    var msg = this.compilemsg(index);
    this.socialSharing.share(msg, null, null, null);
  }


HTML CODE

<div text-center *ngIf="post; let i = index;">
        <ion-col  class="share" size="6" text-right [ngClass]="{ 'show-favorite': isFavorite }" >
              <ion-icon name="share-alt" size="large" class="icon-share-alt" (click)="regularShare(i)"></ion-icon>
        </ion-col>
</div>

Apparently if i comment the declaration on the construct the page will load otherwise it won't load

1

1 Answers

1
votes

Please try this, i did't tried it myself, but hopefully it will work.

installation

ionic cordova plugin add cordova-plugin-x-socialsharing
npm install @ionic-native/social-sharing

Then try to run your code ( If that does not work, try to run following code and see if that works. )

import { SocialSharing } from '@ionic-native/social-sharing/ngx';

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
});

// Share via email
this.socialSharing.shareViaEmail('Body', 'Subject', ['[email protected]']).then(() => {
  // Success!
}).catch(() => {
  // Error!
});

The above approach is basically from ionic documentation so it should work .... https://ionicframework.com/docs/native/social-sharing#installation