0
votes

I'm getting the following errors (from the EmailComposer phonegap plugin) when i try to build from Xcode. I'm not familiar with Obj-C so i'm not sure if this is the result of an error i've made or if it is because the plugin is out-dated. I'm using the latest version of Phonegap (3?) & Xcode 4.6.3.

  • EmailComposer.m:132:6: 'release' is unavailable: not available in automatic reference counting mode
  • EmailComposer.m:132:6: ARC forbids explicit message send of 'release'
  • EmailComposer.m:175:21: Cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast
  • EmailComposer.m:179:11: Cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast
1
I guess the plugin is still not been modified to support PhoneGap 3.0. Its nearby support will be i guess PhoneGap 2.6.0. - Ashis Kumar

1 Answers

0
votes

Try like this..

I used this following plugin file with cordova-2.7.0 and xcode 4.6. It works fine for me.

Take a plugin files name as EmailComposer and copy the below code in EmailComposer.h file

#import <MessageUI/MFMailComposeViewController.h>
#import <Cordova/CDVPlugin.h>
@interface EmailComposer : CDVPlugin < MFMailComposeViewControllerDelegate > {    
}

- (void) showEmailComposer:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

- (void) openApplication:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

@end

And copy the below code in EmailComposer.m file

#import "EmailComposer.h"
@implementation EmailComposer

- (void) openApplication:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[arguments objectAtIndex:1]]]];
}

- (void) showEmailComposer:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{   
// NSUInteger argc = [arguments count];

NSString* toRecipientsString = [arguments objectAtIndex:1];//[options valueForKey:@"toRecipienthellos"];
NSString* ccRecipientsString = [options valueForKey:@"ccRecipients"];
NSString* bccRecipientsString = [options valueForKey:@"bccRecipients"];
NSString* subject = [options valueForKey:@"subject"];
NSString* body = [options valueForKey:@"body"];
NSString* isHTML = [options valueForKey:@"bIsHTML"];

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

// Set subject
if(subject != nil)
    [picker setSubject:subject];
// set body
if(body != nil)
{
    if(isHTML != nil && [isHTML boolValue])
    {
        [picker setMessageBody:body isHTML:YES];
    }
    else
    {
        [picker setMessageBody:body isHTML:NO];
    }
}

// Set recipients
if(toRecipientsString != nil)
{
    [picker setToRecipients:[ toRecipientsString componentsSeparatedByString:@","]];
}
if(ccRecipientsString != nil)
{
    [picker setCcRecipients:[ ccRecipientsString componentsSeparatedByString:@","]]; 
}
if(bccRecipientsString != nil)
{
    [picker setBccRecipients:[ bccRecipientsString componentsSeparatedByString:@","]];
}

if (picker != nil) {    
    [self.viewController presentModalViewController:picker animated:YES];
}
[picker release];
}

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
// Notifies users about errors associated with the interface
int webviewResult = 0;

switch (result)
{
    case MFMailComposeResultCancelled:
        webviewResult = 0;
        break;
    case MFMailComposeResultSaved:
        webviewResult = 1;
        break;
    case MFMailComposeResultSent:
        webviewResult =2;
        break;
    case MFMailComposeResultFailed:
        webviewResult = 3;
        break;
    default:
        webviewResult = 4;
        break;
}

[self.viewController dismissModalViewControllerAnimated:YES];

NSString* jsString = [[NSString alloc] initWithFormat:@"window.plugins.emailComposer._didFinishWithResult(%d);",webviewResult];
[self writeJavascript:jsString];
[jsString release];

 }

 @end