Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

AppFusion - 6 in 1!
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-27-2012, 06:48 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 65
Default in app sms and email advice please

I have.... actually ill just paste some code.
.H
Code:
#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface ViewController : UIViewController<UIAlertViewDelegate,MFMailComposeViewControllerDelegate>
...
@end
.M
Code:
called from a button
...{MFMessageComposeViewController *smsController = [[MFMessageComposeViewController alloc]init];
        if ([MFMessageComposeViewController canSendText]) {
            smsController.body=[[alert textFieldAtIndex:0]text];
            smsController.recipients = [NSArray arrayWithObjects: @"kMYSMS",nil];
            smsController.messageComposeDelegate =nil;
            [self presentModalViewController:smsController animated:YES];

}
-(void)messageComposeViewController:(MFMessageComposeViewController *)smsController didFinishWithResult:(MessageComposeResult)result {
    if(result == MessageComposeResultCancelled) {
        //Message cancelled
    } else if(result == MessageComposeResultSent) {
        //Message sent
    }
    
    [self dismissModalViewControllerAnimated:YES];
}

first question is i want to add some other text into the message body field
i.e "some initial text here" and then [alert textFieldAtIndex:0]text].

When i try and send text on my device it launches the sms app but slowly, it then instantly dismisses the keyboard and text input field. I have to click on top To: field to bring the compose box back on screen. I also must send the sms and the cancel button does not work.

so second question is how can i enable the cancel button once sms is launched
or better still how can I prevent the sms app being launched and just send the sms direct from the uialertview that initializes it?

Last edited by ryantcb; 01-27-2012 at 07:36 PM.
ryantcb is offline   Reply With Quote
Old 01-28-2012, 12:26 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,002
Default

What's "alert" in that code? In what method exactly is that code (you just said "from a button"). Also, you're setting the delegate to nil, 'didFinishWithResult' wont be called.
baja_yu is offline   Reply With Quote
Old 01-28-2012, 03:20 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 65
Default

Sorry the action that calls it is a button in a uialertview. Alert is the name of that uialertview. I didn't spot that I set delegate to nil, so thanks.
ryantcb is offline   Reply With Quote
Old 01-28-2012, 03:38 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,002
Default

Again, which method of the alertview delegate? alertView:clickedButtonAtIndex:, alertView:willDismissWithButtonIndex: or alertView:didDismissWithButtonIndex:
baja_yu is offline   Reply With Quote
Old 01-28-2012, 06:15 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 65
Default

clickedButtonAtIndex

Quote:
- (void)alertViewUIAlertView *)alert clickedButtonAtIndexNSInteger)buttonIndex{
NSString *buttonTitle = [alert buttonTitleAtIndex:buttonIndex];



if ((alert.tag==1)&&([buttonTitle isEqualToString:@"ok"])&&([[[alert textFieldAtIndex:0]text]isEqualToString:@"pass"])){

[self popUpmemberAlert];

NSLog(@"Enter");
}else if ((alert.tag==1)&&([buttonTitle isEqualToString:@"ok"])&&(![[[alert textFieldAtIndex:0]text]isEqualToString:@"pass"])) {

NSLog(@"Failed");
} if ((alert.tag==2)&&([buttonTitle isEqualToString:@"SMS"])){
/////////

MFMessageComposeViewController *smsController = [[MFMessageComposeViewController alloc]init];
if ([MFMessageComposeViewController canSendText]) {
smsController.body=[[alert textFieldAtIndex:0]text];
smsController.recipients = [NSArray arrayWithObjects: kMYSMS,nil];
smsController.messageComposeDelegate = nil;
[self presentModalViewController:smsController animated:YES];


}

NSLog(@"sms");}
else if ((alert.tag==2)&&([buttonTitle isEqualToString:@"email"])){

NSArray *emailArray =[NSArray arrayWithObjects:kmyEmail, nil];
MFMailComposeViewController *emailController = [[MFMailComposeViewController alloc]init];
if ([MFMailComposeViewController canSendMail]) {
[emailController setSubject:@"reg for email"];
[emailController setToRecipients:emailArray];
[emailController setMessageBody:[[alert textFieldAtIndex:0]text] isHTML:NO];
[emailController setMailComposeDelegate:nil];
[self presentModalViewController:emailController animated:YES];


}


}

Last edited by ryantcb; 01-28-2012 at 06:20 PM.
ryantcb is offline   Reply With Quote
Old 01-28-2012, 06:53 PM   #6 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,002
Default

Right. You are presenting a new modal view controller before the alertview is dismissed. Move the code from the clickedButtonAtIndex method to alertView:didDismissWithButtonIndex. Also, you mail and message compose delegate as still set to nil instead of self.
baja_yu is offline   Reply With Quote
Old 01-29-2012, 07:29 AM   #7 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 65
Default

I have fixed it, Thank you for your help
ryantcb is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 660
22 members and 638 guests
ADY, bandley, BrianSlick, Creativ, dacapo, Dattee, e2applets, gbenna, HDshot, IphoneSdk, iseff, jakerocheleau, jbro, joeallenpro, kampftrinker, linkmx, nimesh_158, Reyna, ukneeq, yurikus
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 160,619
Threads: 89,833
Posts: 383,490
Top Poster: BrianSlick (7,244)
Welcome to our newest member, yurikus
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:41 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0