For an iOS App, We had a requirement to find whether cancel button is called or send button is called from the email composer using shareViaEmail.
We have just customized the SocialSharing.m and ng-cordova.js to achieve this.
This may be just a quick fix. We need this feature to be added in the feature release of plugins.
Below we are pasting the code we customized.
SocialSharing.m
Search for this method
- (void) mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
And replace it completely with below code.
/**
- Delegate will be called after the mail composer did finish an action
- to dismiss the view.
*/
-
(void) mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error {//bool ok = result == MFMailComposeResultSent;
int ok = 0;
if(result == MFMailComposeResultSent){
ok = 1;
} else if (result == MFMailComposeResultCancelled){
ok = 2;
}[self.viewController dismissViewControllerAnimated:YES completion:^{[self cycleTheGlobalMailComposer];}];
CDVPluginResult * pluginResult;
if(ok == 1) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:ok];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:ok];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:_command.callbackId];
}
ng-cordova.js
Search for this method
shareViaEmail: function (message, subject, toArr, ccArr, bccArr, fileArr)
And replace it completely with below code
{
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 (res) {
q.resolve(res);
}, function (res) {
q.reject(res);
});
return q.promise;
}
Now,
if cancel is clicked, failure callback will be called, response data = 2
if send button is clicked and mail sent successfully, success callback will be called, response data = 1
if send button is clicked and sending failed, failure callback will be called, response data = 0
This is just a quick fix, please add them in feature plugin request.
Thanks.