1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147// install : cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git
// link : https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
// NOTE: shareViaEmail -> if user cancels sharing email, success is still called
// TODO: add support for iPad
angular.module('ngCordova.plugins.socialSharing', [])
.factory('$cordovaSocialSharing', ['$q', '$window', function ($q, $window) {
return {
share: function (message, subject, file, link) {
var q = $q.defer();
subject = subject || null;
file = file || null;
link = link || null;
$window.plugins.socialsharing.share(message, subject, file, link, function () {
q.resolve(true);
}, function () {
q.reject(false);
});
return q.promise;
},
shareViaTwitter: function (message, file, link) {
var q = $q.defer();
file = file || null;
link = link || null;
$window.plugins.socialsharing.shareViaTwitter(message, file, link, function () {
q.resolve(true);
}, function () {
q.reject(false);
});
return q.promise;
},
shareViaWhatsApp: function (message, file, link) {
var q = $q.defer();
file = file || null;
link = link || null;
$window.plugins.socialsharing.shareViaWhatsApp(message, file, link, function () {
q.resolve(true);
}, function () {
q.reject(false);
});
return q.promise;
},
shareViaFacebook: function (message, file, link) {
var q = $q.defer();
message = message || null;
file = file || null;
link = link || null;
$window.plugins.socialsharing.shareViaFacebook(message, file, link, function () {
q.resolve(true);
}, function () {
q.reject(false);
});
return q.promise;
},
shareViaFacebookWithPasteMessageHint: function (message, file, link, pasteMessageHint) {
var q = $q.defer();
file = file || null;
link = link || null;
$window.plugins.socialsharing.shareViaFacebookWithPasteMessageHint(message, file, link, pasteMessageHint, function () {
q.resolve(true);
}, function () {
q.reject(false);
});
return q.promise;
},
shareViaSMS: function (message, commaSeparatedPhoneNumbers) {
var q = $q.defer();
$window.plugins.socialsharing.shareViaSMS(message, commaSeparatedPhoneNumbers, function () {
q.resolve(true);
}, function () {
q.reject(false);
});
return q.promise;
},
shareViaEmail: function (message, subject, toArr, ccArr, bccArr, fileArr) {
var q = $q.defer();
toArr = toArr || null;
ccArr = ccArr || null;
bccArr = bccArr || null;
fileArr = fileArr || null;
$window.plugins.socialsharing.shareViaEmail(message, subject, toArr, ccArr, bccArr, fileArr, function () {
q.resolve(true);
}, function () {
q.reject(false);
});
return q.promise;
},
shareVia: function (via, message, subject, file, link) {
var q = $q.defer();
message = message || null;
subject = subject || null;
file = file || null;
link = link || null;
$window.plugins.socialsharing.shareVia(via, message, subject, file, link, function () {
q.resolve(true);
}, function () {
q.reject(false);
});
return q.promise;
},
canShareViaEmail: function () {
var q = $q.defer();
$window.plugins.socialsharing.canShareViaEmail(function () {
q.resolve(true);
}, function () {
q.reject(false);
});
return q.promise;
},
canShareVia: function (via, message, subject, file, link) {
var q = $q.defer();
$window.plugins.socialsharing.canShareVia(via, message, subject, file, link, function (success) {
q.resolve(success);
}, function (error) {
q.reject(error);
});
return q.promise;
},
available: function () {
var q = $q.defer();
window.plugins.socialsharing.available(function (isAvailable) {
if (isAvailable) {
q.resolve();
}
else {
q.reject();
}
});
return q.promise;
}
};
}]);