Error found - too many arguments to method call expected 1 have 2 - in app email - xcode4.3

There seems to be an error with my coding, and it says that there are to many nils or something
I need help
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc]init];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObject:#"nicole#aandtlegal.com", nil]];
[composer setSubject:nil];[composer setMailComposeDelegate:self];
[composer setMessageBody:nil isHTML:YES];
[composer setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

Try this code:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello!"];
NSArray *toRecipients = [NSArray arrayWithObject:#"example#example.com"];
[picker setToRecipients:toRecipients];
NSString *emailBody = [NSString stringWithString:#"Hello!"];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[self presentModalViewController:picker animated:YES];
[picker release];

Related

Application tried to present a nil modal view controller on target in iOS 10?

I am implementing MFMailComposeViewController in my application when I click on my mail button I am get the below error.
Application tried to present a nil modal view controller on target strong text
Here's my code:
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleShortVersionString"];
NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleVersion"];
mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.navigationBar.tintColor = [UIColor blackColor];
[mailComposer.navigationBar setTitleTextAttributes:
#{NSForegroundColorAttributeName:[UIColor blackColor]}];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:#"Co - Contact Us"];
[mailComposer setToRecipients:#[#"contact#co.org"]];
NSString *supportText = #"Enter your comment here:\n\n\n\n\n";
supportText = [supportText stringByAppendingString:[NSString stringWithFormat:#"iOS Version: %#\nCorner Version:%#\nBuild:%#\n\n",iOSVersion,version, build]];
[mailComposer setMessageBody:supportText isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
What's wrong with my code. Please help
If device has not configured mail or using simulator can lead to crash or exception.
mailComposer = [[MFMailComposeViewController alloc] init];
above line of code can cause problem. in simulator initializer method may return NULL or nil.
so, just check for canSendMail before presenting modal viewController:
Like,
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleShortVersionString"];
NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleVersion"];
mailComposer = [[MFMailComposeViewController alloc]init];
if ([MFMailComposeViewController canSendMail] && mailComposer) {
mailComposer.navigationBar.tintColor = [UIColor blackColor];
[mailComposer.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor blackColor]}];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:#"Corner - Contact Us"];
[mailComposer setToRecipients:#[#"contact#corner.org"]];
NSString *supportText = #"Enter your comment here:\n\n\n\n\n";
supportText = [supportText stringByAppendingString:[NSString stringWithFormat:#"iOS Version: %#\nCorner Version:%#\nBuild:%#\n\n",iOSVersion,version, build]];
[mailComposer setMessageBody:supportText isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
}

MFMailCompose issues with iPhone5

Is there a new way to present a MFMailComposeViewController for the iPhone 5? I'm working with a 4 and 5 side by side and the 4 presents/works correctly, yet for the 5 it doesn't even hit the code:
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setToRecipients:[NSArray arrayWithObject:#"support#myemail.com"]];
[mailViewController setSubject:#"Feedback"];
[mailViewController setMessageBody:#"" isHTML:NO];
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
}
Is your mail set up for the iPhone5?
Strange, it works perfect for me on iPhone 5!
MFMailComposeViewController *mailVC = [MFMailComposeViewController mailComposeViewControllerWithRecipe:self.recipe];
if (mailVC) {
mailVC.mailComposeDelegate = self;
[self presentModalViewController:mailVC animated:YES];
}
what exactly do you mean "it doesn't even hit the code"? Maybe yours
([MFMailComposeViewController canSendMail])
is false or problem in some abother place

How to fill email with To and Subject in iPhone?

I have a button in my app called contact Us! Is there a way to open up the Eamil client in iPhone filled with To and Subject that I provide?
You will want to use the MFMailComposeViewController class. Here's the relevant part from Apple's MailComposer example:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello from California!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"first#example.com"];
[picker setToRecipients:toRecipients];
[self presentModalViewController:picker animated:YES];
[picker release];
The MailComposer sample also shows you how to open the external mail app:
NSString *recipients = #"mailto:first#example.com&subject=Hello from California!";
NSString *body = #"&body=It is raining in sunny California!";
NSString *email = [NSString stringWithFormat:#"%#%#", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
Check out MFMailComposeViewController. You can set the Subject, To Field, and even populate the body with HTML.
Sure you can.
- (void)emailExport:(NSString *)filePath
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// Set the subject of email
[picker setSubject:#"My desired subject"];
// Add email addresses
// Notice three sections: "to" "cc" and "bcc"
NSString *valueForEmail = #"myEmail#gmail.com";
NSString *valueForCCEmail = #"myCcEmail";
if( valueForEmail == nil || [valueForEmail isEqualToString:#""])
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Please set an email address before sending a time entry!" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return;
}
else {
[picker setToRecipients:[NSArray arrayWithObjects:valueForEmail, nil]];
}
if(valueForCCEmail != nil || ![valueForCCEmail isEqualToString:#""])
{
[picker setCcRecipients:[NSArray arrayWithObjects:valueForCCEmail, nil]];
}
// Fill out the email body text
NSString *emailBody = #"My email body text.";
// This is not an HTML formatted email
[picker setMessageBody:emailBody isHTML:NO];
// Show email view
[self presentModalViewController:picker animated:YES];
// Release picker
[picker release];
}

Why the difference in UIAlertView?

I have the following code, which works:
// Load new game screen
-(IBAction)newGame_button:(id)sender {
myAlert = [[UIAlertView alloc]
initWithTitle:#"Varning"
message:#"Om du går vidare kommer pågående spel stoppas och nollställas!"
delegate:self
cancelButtonTitle:#"Tillbaka"
otherButtonTitles:#"Fortsätt", nil];
myAlert.tag=kTagNewGame;
[myAlert show];
[myAlert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
switch(myAlert.tag ) {
case kTagContinueGame:
NSLog(#"kTagContinueGame");
NSMutableArray *continueGameArray = [[NSMutableArray alloc] initWithCapacity:0];
AccessCurrentGameData *getCurrentGameInfo = [AccessCurrentGameData new];
continueGameArray = [getCurrentGameInfo continueTheCurrentGame];
[getCurrentGameInfo release];
[continueGameArray retain];
[continueGameArray release];
QandA_ViewController * temp = [[QandA_ViewController alloc] init];
[self setQanda_ViewController:temp];
[temp release];
[[self navigationController] pushViewController:qanda_ViewController animated:YES];
break;
case kTagNewGame:
NSLog(#"kTagNewGame");
AccessCurrentGameData *zeroCurrentGameFileFunction = [AccessCurrentGameData new];
[zeroCurrentGameFileFunction firstCreationOrRestoreOfGameDataFile];
[zeroCurrentGameFileFunction release];
NewGameViewController * temp2 = [[NewGameViewController alloc] init];
[self setNewGameViewController:temp2];
[temp2 release];
[[self navigationController] pushViewController:newGameViewController animated:YES];
break;
default:
break;
}
}
However, when I remove the NSLog's I get the following error:
Expected expression before 'NSMutableArray'
I do not understand why this is happening. I can probably leave the NSLog's but why?
The problem is that variable declaration cannot directly follow case label. To solve that I usually put the whole case block in {}:
...
case kTagNewGame:
{
AccessCurrentGameData *zeroCurrentGameFileFunction = [AccessCurrentGameData new];
[zeroCurrentGameFileFunction firstCreationOrRestoreOfGameDataFile];
[zeroCurrentGameFileFunction release];
NewGameViewController * temp2 = [[NewGameViewController alloc] init];
[self setNewGameViewController:temp2];
[temp2 release];
[[self navigationController] pushViewController:newGameViewController animated:YES];
break;
}
...

How do I change modalTransitionStyle?

I am currently using this code to bring up an info window
-(IBAction)showInfo:(id)sender {
InfoView *info = [[InfoView alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
[self presentModalViewController:info animated:YES];
[info release];
}
It currently uses the default transition style, UIModalTransitionStyleCoverVertical, and I would like to make it use a different transition style, UIModalTransitionStyleFlipHorizontal for example, how do I do this?
from apple documentation
http://developer.apple.com/iphone/library/samplecode/AddMusic/Listings/Classes_MainViewController_m.html#//apple_ref/doc/uid/DTS40008845-Classes_MainViewController_m-DontLinkElementID_6
MusicTableViewController *controller = [[MusicTableViewController alloc] initWithNibName: #"MusicTableView" bundle: nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController: controller animated: YES];
[controller release];
- (IBAction)next {
page2 *page2_xib = [[page2 alloc] init];
page2_xib.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//page2_xib.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//page2_xib.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//page2_xib.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:page2_xib animated:YES];
}