Phonegap EmailComposer插件错误

时间:2013-09-11 02:58:08

标签: objective-c plugins cordova

当我尝试使用Xcode构建时,我收到以下错误(from the EmailComposer phonegap plugin)。我不熟悉Obj-C,所以我不确定这是由于我犯了错误还是因为插件已过时而造成的。我使用的是最新版本的Phonegap(3?)& Xcode 4.6.3。

  • EmailComposer.m:132:6:'发布'不可用:在自动参考计数模式下不可用
  • EmailComposer.m:132:6:ARC禁止发布'发布'
  • EmailComposer.m:175:21:投射Objective-C指针类型' NSString *'到C指针类型' CFStringRef' (又名' const struct __CFString *')需要桥接演员
  • EmailComposer.m:179:11:C指针类型的转换' CFStringRef' (又名' const struct __CFString *')到Objective-C指针类型' NSString *'需要一个桥接演员

1 个答案:

答案 0 :(得分:0)

试试这样..

我在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