-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSMSComposer.m
executable file
·85 lines (65 loc) · 2.38 KB
/
SMSComposer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// ClipboardPlugin.m
// Clipboard plugin for PhoneGap
//
// Created by Grant Sanders on 12/25/2010.
//
#import "SMSComposer.h"
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMessageComposeViewController.h>
@implementation SMSComposer
- (void)showSMSComposer:(NSArray*)arguments withDict:(NSDictionary*)options
{
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
if (![messageClass canSendText]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notice" message:@"SMS Text not available."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
return;
}
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notice" message:@"SMS Text not available."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
return;
}
NSString* body = [options valueForKey:@"body"];
NSString* toRecipientsString = [options valueForKey:@"toRecipients"];
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
if(body != nil)
picker.body = [options valueForKey:@"body"];
if(toRecipientsString != nil)
[picker setRecipients:[ toRecipientsString componentsSeparatedByString:@","]];
[[ super appViewController ] presentModalViewController:picker animated:YES];
[picker release];
}
// Dismisses the composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
// Notifies users about errors associated with the interface
int webviewResult = 0;
switch (result)
{
case MessageComposeResultCancelled:
webviewResult = 0;
break;
case MessageComposeResultSent:
webviewResult = 1;
break;
case MessageComposeResultFailed:
webviewResult = 2;
break;
default:
webviewResult = 3;
break;
}
[[ super appViewController ] dismissModalViewControllerAnimated:YES];
NSString* jsString = [[NSString alloc] initWithFormat:@"window.plugins.smsComposer._didFinishWithResult(%d);",webviewResult];
[self writeJavascript:jsString];
[jsString release];
}
@end