forked from hermwong/Wikipedia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Christiansen
committed
Jul 4, 2012
1 parent
6a11345
commit 5d4e057
Showing
9 changed files
with
372 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// EmailComposer.h | ||
// | ||
// | ||
// Created by Jesse MacFadyen on 10-04-05. | ||
// Copyright 2010 Nitobi. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <MessageUI/MFMailComposeViewController.h> | ||
#ifdef CORDOVA_FRAMEWORK | ||
#import <Cordova/CDVPlugin.h> | ||
#else | ||
#import "CDVPlugin.h" | ||
#endif | ||
|
||
|
||
@interface EmailComposer : CDVPlugin < MFMailComposeViewControllerDelegate > { | ||
|
||
|
||
} | ||
|
||
- (void) showEmailComposer:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// window.plugins.emailComposer | ||
|
||
function EmailComposer() { | ||
this.resultCallback = null; // Function | ||
} | ||
|
||
EmailComposer.ComposeResultType = { | ||
Cancelled:0, | ||
Saved:1, | ||
Sent:2, | ||
Failed:3, | ||
NotSent:4 | ||
} | ||
|
||
|
||
|
||
// showEmailComposer : all args optional | ||
|
||
EmailComposer.prototype.showEmailComposer = function(subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML) { | ||
var args = {}; | ||
if(toRecipients) | ||
args.toRecipients = toRecipients; | ||
if(ccRecipients) | ||
args.ccRecipients = ccRecipients; | ||
if(bccRecipients) | ||
args.bccRecipients = bccRecipients; | ||
if(subject) | ||
args.subject = subject; | ||
if(body) | ||
args.body = body; | ||
if(bIsHTML) | ||
args.bIsHTML = bIsHTML; | ||
|
||
cordova.exec(null, null, "EmailComposer", "showEmailComposer", [args]); | ||
} | ||
|
||
// this will be forever known as the orch-func -jm | ||
EmailComposer.prototype.showEmailComposerWithCB = function(cbFunction,subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML) { | ||
this.resultCallback = cbFunction; | ||
this.showEmailComposer.apply(this,[subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML]); | ||
} | ||
|
||
EmailComposer.prototype._didFinishWithResult = function(res) { | ||
this.resultCallback(res); | ||
} | ||
|
||
|
||
|
||
cordova.addConstructor(function() { | ||
if(!window.plugins) | ||
{ | ||
window.plugins = {}; | ||
} | ||
|
||
// shim to work in 1.5 and 1.6 | ||
if (!window.Cordova) { | ||
window.Cordova = cordova; | ||
}; | ||
|
||
window.plugins.emailComposer = new EmailComposer(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// | ||
// EmailComposer.m | ||
// | ||
// | ||
// Created by Jesse MacFadyen on 10-04-05. | ||
// Copyright 2010 Nitobi. All rights reserved. | ||
// | ||
|
||
#import "EmailComposer.h" | ||
|
||
|
||
@implementation EmailComposer | ||
|
||
|
||
- (void) showEmailComposer:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options | ||
{ | ||
// NSUInteger argc = [arguments count]; | ||
|
||
NSString* toRecipientsString = [options valueForKey:@"toRecipients"]; | ||
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:@","]]; | ||
} | ||
|
||
// Attach an image to the email | ||
// NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"]; | ||
// NSData *myData = [NSData dataWithContentsOfFile:path]; | ||
// [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"]; | ||
|
||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title></title> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" /> | ||
<meta charset="utf-8"> | ||
|
||
|
||
<!-- iPad/iPhone specific css below, add after your main css > | ||
<link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="ipad.css" type="text/css" /> | ||
<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" /> | ||
--> | ||
<!-- If your application is targeting iOS BEFORE 4.0 you MUST put json2.js from http://www.JSON.org/json2.js into your www directory and include it here --> | ||
<script type="text/javascript" charset="utf-8" src="cordova-1.6.0.js"></script> | ||
|
||
<script type="text/javascript" charset="utf-8" src="EmailComposer.js"></script> | ||
<script type="text/javascript"> | ||
|
||
|
||
// If you want to prevent dragging, uncomment this section | ||
/* | ||
function preventBehavior(e) | ||
{ | ||
e.preventDefault(); | ||
}; | ||
document.addEventListener("touchmove", preventBehavior, false); | ||
*/ | ||
|
||
/* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch. | ||
see http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html | ||
for more details -jm */ | ||
/* | ||
function handleOpenURL(url) | ||
{ | ||
// TODO: do something with the url passed in. | ||
} | ||
*/ | ||
|
||
function onBodyLoad() | ||
{ | ||
document.addEventListener("deviceready", onDeviceReady, false); | ||
} | ||
|
||
/* When this function is called, Cordova has been initialized and is ready to roll */ | ||
/* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch. | ||
see http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html | ||
for more details -jm */ | ||
function onDeviceReady() | ||
{ | ||
// do your thing! | ||
navigator.notification.alert("Cordova is working") | ||
|
||
var args; | ||
cordova.exec(null, null, "EmailComposer", "showEmailComposer", [args]); | ||
|
||
|
||
|
||
} | ||
|
||
</script> | ||
</head> | ||
<body onload="onBodyLoad()"> | ||
<h1>Hey, it's Cordova!</h1> | ||
<p>Don't know how to get started? Check out our <em><a target="_blank" href="http://docs.phonegap.com/en/edge/guide_getting-started_ios_index.md.html#Getting%20Started%20with%20iOS">Getting Started Guide</a></em> | ||
<br /> | ||
<ol> | ||
<li>Check your console log for any white-list rejection errors.</li> | ||
<li>Add your allowed <strong>hosts</strong> in Cordova.plist/ExternalHosts (wildcards OK, don't enter the URL scheme)</li> | ||
</ol> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Added Cordova 1.5 support March 2012 - @RandyMcMillan | ||
|
||
• You will need to add MessageUI.framework to your project if it is not already included. | ||
|
||
• Just add the EmailComposer.h EmailComposer.m files to your Plugins Folder. | ||
|
||
• Place the EmailComposer.js file in your app root, and include it from your html. | ||
|
||
• Add to Cordova.plist Plugins: key EmailComposer value EmailComposer | ||
|
||
• This is intended to also demonstrate how to pass arguments to native code using the options/map object. | ||
|
||
• Please review the js file to understand the interface you can call, and reply with any questions. | ||
|
||
Cordova.exec(null, null, "EmailComposer", "showEmailComposer", [args]); |
Oops, something went wrong.