试试这样。。
我将以下插件文件与 cordova-2.7.0 和 xcode 4.6 一起使用。这对我来说可以。
取一个插件文件名作为 EmailComposer 并将以下代码复制到 EmailComposer.h 文件中
#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
并将以下代码复制到 EmailComposer.m 文件中
#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