Hi I’m trying to make a SMS native extension for adobe AIR.
I Havnt coded in objective-c before but everything works fine except for the fact that the SMS window won’t close when pressing send or cancel. Below is the main section of code but ask me if you need any more info. Thanks for reading.
also why is xcode telling me :”Method in protocol not implemented” for the second line ?
#import "SMSComposerHelper.h"
@implementation SMSComposerHelper
//Event name
static NSString *event_name = @"SMS_COMPOSER_EVENT";
-(void) sendSMS:(NSString *)toRecipient
messageBody:(NSString *)messageBody
{
FREDispatchStatusEventAsync(context, (uint8_t*)[event_name UTF8String], (uint8_t*)[@"WILL_SHOW_MAIL_COMPOSER" UTF8String]);
MFMessageComposeViewController *smsComposer = [[MFMessageComposeViewController alloc] init];
smsComposer.messageComposeDelegate = self;
//make string into array
NSArray *recipientArray;
recipientArray = [NSArray arrayWithObjects: toRecipient, nil];
smsComposer.body = messageBody;
smsComposer.recipients = recipientArray;
//show sms composer
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:smsComposer animated:YES];
}
// Dismisses the sms composition interface when users tap Cancel or Send.
-(void) smsComposeController: (MFMessageComposeViewController*)controller didFinishWithResult: (MessageComposeResult)result error:(NSError*)error
{
NSString *event_info = @"";
// Notifies users about errors associated with the interface
switch (result)
{
case MessageComposeResultCancelled:
event_info = @"SMS_CANCELED";
break;
case MessageComposeResultSent:
event_info = @"SMS_SENT";
break;
case MessageComposeResultFailed:
event_info = @"SMS_FAILED";
break;
default:
event_info = @"SMS_UNKNOWN";
break;
}
FREDispatchStatusEventAsync(context, (uint8_t*)[event_name UTF8String], (uint8_t*)[event_info UTF8String]);
FREDispatchStatusEventAsync(context, (uint8_t*)[event_name UTF8String], (uint8_t*)[@"WILL_HIDE_SMS_COMPOSER" UTF8String]);
context = nil;
//hide mail composer
[[[[UIApplication sharedApplication] keyWindow] rootViewController] dismissModalViewControllerAnimated:YES];
}
-(void)setContext:(FREContext)ctx {
context = ctx;
}
@end
RESPONSE :
Omar thankyou so much for your answer and for answering so quickly!
First I tried your solution of using
[controller dismissModalViewControllerAnimated:YES];
but this did nothing so I changed it back.
My header already was :
@interface SMSComposerHelper : NSObject<MFMessageComposeViewControllerDelegate> {
So I decided to focus on fixing the warning.
The warning was solved by changing :
-(void) smsComposeController: (MFMessageComposeViewController*)controller didFinishWithResult: (MessageComposeResult)result error:(NSError*)error
to:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
I would love to know why this worked ? do you know Omar ?
So I solved the warning but it still didn’t dismiss.
So I tried your suggestion again:
[controller dismissModalViewControllerAnimated:YES];
AND IT WORKED !!!!
thanks so much man. You don’t know how many hours I was stuck for.
I will be happy to accept your answer.
Instead of
write
Also for the warning
Go to
SMSComposerHelper.hAnd add the following
instead of