[RESOLVED] cordovaSocialSharing in ionic not working


#1

Hi Guys, I’m using the plugin cordovaSocialShare of NgCordova to make sharing on social networks in my application. The problem is that I don’t have actions returned, and when analyzing the ADB logs, it returns me the following error:

I / chromium (3635): [INFO: ISLAND (20306)] "TypeError: Can not call method 'canShareVia' of undefined
I / chromium (3635): Scope at $ scope.shareViaWhatsapp. (File: ///android_asset/www/js/app.js: 22: 31)

Look at the code:

HTML:

<ion-option-button class="button-dark button-facebook" ng-click="shareAnywhere()">
    <i class="icon ion-social-facebook icon-facebook"></i>
</ion-option-button>

AngularJS:

$ionicPlatform.ready(function(){
$scope.shareViaWhatsapp = function(message, image, link) {
    $cordovaSocialSharing.canShareVia("whatsapp", message, image, link).then(function(result) {
        $cordovaSocialSharing.shareViaWhatsapp(message, image, link);
    }, function(error) {
        alert("Cannot share on Whatsapp");
    });
}

$scope.shareAnywhere = function() {
    $cordovaSocialSharing.share("This is your message", "This is your subject", "www/imagefile.png", "http://blog.nraboy.com");
}
});

Help me please?


#2

maybe you forgot to inject $cordovaSocialSharinginto your controller


#3

Hello, I have checked this and it’s all right, $cordovaSocialSharing is injected in my controller, see:

App.controller("AppCtrl", ["$scope", "JsonNews", "$log", "$cordovaSocialSharing", "$ionicPlatform", AppCtrl]);
function AppCtrl($scope, JsonNews, $log, $cordovaSocialSharing, $ionicPlatform, cidade){

#4

Anyway, again, I decided the problem by myself …

The result:

In command line:

ionic plugin add cordova-plugin-SocialSharing

AngularJS:

$scope.share = function($title, $excerpt, $permalink) {
      $ionicListDelegate.closeOptionButtons();
      window.plugins.socialsharing.share($title, $excerpt, null, $permalink);
}

HTML:

<ion-option-button class="button-positive button-share" ng-click="share('{{item.title}}', '{{item.excerpt}}', '{{item.permalink}}')">
        <i class="icon ion-android-share-alt"></i>
</ion-option-button>

#5

OK, so you decided to use the Cordova plugin directly rather than through the Angular wrapper.