Skip to content

Instantly share code, notes, and snippets.

@yellowandy
Created December 16, 2010 19:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yellowandy/743859 to your computer and use it in GitHub Desktop.
Save yellowandy/743859 to your computer and use it in GitHub Desktop.
SMS Dialogue support for TI
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#ifdef USE_TI_UISMSDIALOG
#import "TiProxy.h"
#import <MessageUI/MessageUI.h>
@interface TiUISmsDialogProxy : TiProxy<MFMessageComposeViewControllerDelegate>
{
}
- (void)send:(id)args;
@property(nonatomic,readonly) NSNumber *SENT;
@property(nonatomic,readonly) NSNumber *CANCELLED;
@property(nonatomic,readonly) NSNumber *FAILED;
@end
#endif
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#ifdef USE_TI_UISMSDIALOG
#import "TiBase.h"
#import "TiUISmsDialogProxy.h"
#import "TiUtils.h"
#import "TiBlob.h"
#import "TiColor.h"
#import "TiApp.h"
#import "TiFile.h"
#import "Mimetypes.h"
@implementation TiUISmsDialogProxy
- (void) dealloc
{
[super dealloc];
}
-(void)_destroy
{
[super _destroy];
}
- (id)isSupported:(id)args
{
return NUMBOOL([MFMessageComposeViewController canSendText]);
}
- (void)send:(id)args
{
ENSURE_TYPE_OR_NIL(args,NSDictionary);
Class arrayClass = [NSArray class];
NSArray * toArray = [self valueForUndefinedKey:@"toRecipients"];
ENSURE_CLASS_OR_NIL(toArray,arrayClass);
ENSURE_UI_THREAD(send,args);
NSString * subject = [TiUtils stringValue:[self valueForUndefinedKey:@"subject"]];
if (![MFMessageComposeViewController canSendText])
{
NSDictionary *event = [NSDictionary dictionaryWithObjectsAndKeys:NUMINT(MessageComposeResultFailed),@"result",
NUMBOOL(NO),@"success",
@"system can't send sms, are you in the simulator?",@"error",
nil];
[self fireEvent:@"complete" withObject:event];
return;
}
UIColor * barColor = [[TiUtils colorValue:[self valueForUndefinedKey:@"barColor"]] _color];
MFMessageComposeViewController *composer = [[MFMessageComposeViewController alloc] init];
[composer setMessageComposeDelegate: self];
[composer setRecipients:toArray]
[composer setBody:subject];
[picker release];
if (barColor != nil)
{
[[composer navigationBar] setTintColor:barColor];
}
BOOL animated = [TiUtils boolValue:@"animated" properties:args def:YES];
[self retain];
[[TiApp app] showModalController:composer animated:animated];
}
MAKE_SYSTEM_PROP(SENT,MessageComposeResultSent);
MAKE_SYSTEM_PROP(CANCELLED,MessageComposeResultCancelled);
MAKE_SYSTEM_PROP(FAILED,MessageComposeResultFailed);
#pragma mark Delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
{
BOOL animated = YES;
[[TiApp app] hideModalController:controller animated:animated];
[controller autorelease];
controller = nil;
if ([self _hasListeners:@"complete"])
{
NSDictionary *event = [NSDictionary dictionaryWithObjectsAndKeys:NUMINT(result),@"result",
NUMBOOL(result==MessageComposeResultSent),@"success",
nil];
[self fireEvent:@"complete" withObject:event];
}
[self autorelease];
}
@end
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment