Skip to content

Commit

Permalink
Merge pull request phonegap#359 from devgeeks/SMSComposer-update
Browse files Browse the repository at this point in the history
SMSComposer updated for 1.4.x
  • Loading branch information
macdonst committed Feb 22, 2012
2 parents b81a664 + 5e9255f commit bb7338d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
36 changes: 21 additions & 15 deletions iPhone/SMSComposer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ Using this plugin requires [PhoneGap for iPhone](http://github.com/phonegap/phon
1. Add the SMSComposer.h and SMSComposer.m files to your "Plugins" folder in your PhoneGap project
2. Add the SMSComposer.js files to your "www" folder on disk, and add a reference to the .js file after phonegap.js.
3. Add the MessageUI framework to your Xcode project. In Xcode 4, double-click on the target, select "Build Phases" -> "Link Binary with Libraries" -> "+" and select "MessageUI.framework".
4. Add the plugin to the PhoneGap.plist under Plugins (key: "SMSComposer" value: "SMSComposer")

## RELEASE NOTES ##

###20120219 ###
* Fix for deprecations in PhoneGap 1.4.x
* Added PhoneGap.plist instructions in README.md

### 201101112 ###
* Initial release
* Adds SMS text message composition in-app.
Expand All @@ -20,32 +25,33 @@ Using this plugin requires [PhoneGap for iPhone](http://github.com/phonegap/phon
## EXAMPLE USAGE ##

* All parameters are optional.
window.plugins.smsComposer.showSMSComposer();
`window.plugins.smsComposer.showSMSComposer();`


* Passing phone number and message.
window.plugins.smsComposer.showSMSComposer('3424221122', 'hello');
`window.plugins.smsComposer.showSMSComposer('3424221122', 'hello');`

* Multiple recipents are separated by comma(s).
window.plugins.smsComposer.showSMSComposer('3424221122,2134463330', 'hello');
`window.plugins.smsComposer.showSMSComposer('3424221122,2134463330', 'hello');`


* showSMSComposerWithCB takes a callback as its first parameter.
* `showSMSComposerWithCB` takes a callback as its first parameter.
* 0, 1, 2, or 3 will be passed to the callback when the text message has been attempted.

window.plugins.smsComposer.showSMSComposerWithCB(function(result){

if(result == 0)
alert("Cancelled");
else if(result == 1)
alert("Sent");
else if(result == 2)
alert("Failed.");
else if(result == 3)
alert("Not Sent.");
```javascript
window.plugins.smsComposer.showSMSComposerWithCB(function(result){

},'3424221122,2134463330', 'hello');
if(result == 0)
alert("Cancelled");
else if(result == 1)
alert("Sent");
else if(result == 2)
alert("Failed.");
else if(result == 3)
alert("Not Sent.");

},'3424221122,2134463330', 'hello');
````````

* A fully working example as index.html has been added to this repository.
* It is an example of what your www/index.html could look like.
10 changes: 8 additions & 2 deletions iPhone/SMSComposer/SMSComposer.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

@implementation SMSComposer

-(PGPlugin*) initWithWebView:(UIWebView*)theWebView
{
self = (SMSComposer*)[super initWithWebView:theWebView];
return self;
}

- (void)showSMSComposer:(NSArray*)arguments withDict:(NSDictionary*)options
{

Expand Down Expand Up @@ -45,7 +51,7 @@ - (void)showSMSComposer:(NSArray*)arguments withDict:(NSDictionary*)options
if(toRecipientsString != nil)
[picker setRecipients:[ toRecipientsString componentsSeparatedByString:@","]];

[[ super appViewController ] presentModalViewController:picker animated:YES];
[self.viewController presentModalViewController:picker animated:YES];
[picker release];

}
Expand All @@ -72,7 +78,7 @@ - (void)messageComposeViewController:(MFMessageComposeViewController *)controlle
break;
}

[[ super appViewController ] dismissModalViewControllerAnimated:YES];
[self.viewController dismissModalViewControllerAnimated:YES];

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

0 comments on commit bb7338d

Please sign in to comment.