iphone MFMessageComposeViewController, status bar problem - iphone

I'm using the following code to show in-app sms. My app don't have a status bar. (I'm using 320x480 pixels screen in portrait view)
if ([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController* msgController = [[MFMessageComposeViewController alloc] init];
msgController.recipients = [NSArray arrayWithObject:self.globalSMS];
msgController.messageComposeDelegate = self;
[self presentModalViewController:msgController animated:YES];
[msgController release];
}
This is working good to display the message view controller. (But status bar comes back, which is not necessary for me to show)
But the problem is that when I click "Cancel" or "Send", after going back to application, I am seeing white space on the top (in position of status bar) of the screen. And status bar is hidden.
Why is it happening when my status bar is set as hidden in app delegate. How to get rid of white space after showing the in-app sms view.

Hide the status bar after you modal presented the message controller. Something like this:
controller.wantsFullScreenLayout = NO;
[self presentModalViewController:controller animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Also Answered here: MFMessageComposeViewController not properly displayed

I found the answer. We've to set in view controller's viewDidLoad method:
self.wantsFullScreenLayout = YES;

The issue is in portrait view. From what I am seeing if the MFMessageComposeViewController loads in landscape the space isn't there. Then if the orientation changes to portrait the layout is corrected and the space isn't present in portrait.
Note When in landscape the MFMessageComposeViewController is presented by sliding from left to right. I believe that the way the view is presented holds to key to fixing the issue.

MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.body = #"MessageText!!!";
controller.recipients = [NSArray arrayWithObjects:#"123"];
controller.messageComposeDelegate = self;
controller.wantsFullScreenLayout = YES;
[self presentModalViewController:controller animated:YES];
}

Related

MFMessageComposeViewControllerDelegate error - black screen

I'm using the following code to show in-app sms. My app don't have a status bar. (I'm using 320x480 pixels screen in portrait view).
the problem is that when I load the controller, the screen becomes black as you can see from the image...
http://desmond.imageshack.us/Himg211/scaled.php?server=211&filename=schermata092456187alle1.png&res=landing
this is the code:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObject:#"123456789"]; // your recipient number or self for testing
picker.body = #"test";
[self presentModalViewController:picker animated:YES];
Testing the MFMessageComposeViewController is currently not supported in the simulator. The MFMailComposeViewController is though.
Try out your code on an actual device and it will work.

MFMessageComposeViewController pushes my view down 20px. Why? How to fix?

I have an iPhone app which hides the status bar when run. After launching a MFMessageComposeViewController and dismissing it (after either send or cancel) all my previously drawn elements are shifted down 20px. This is clearly to do with the status bar showing when the MFMessageComposeViewController is presented.
Can I either stop this happening or fix it in my (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result method to undo the change?
Thanks :)
OK, turned out I needed to set:
self.wantsFullScreenLayout = YES;
in my view controller. this fixed it. perhaps it's useful to someone else.
After I launch the modal view picker is when I remove the status bar.
You may need to set it to NO when you return.
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.wantsFullScreenLayout = NO;
NSString * currentString = nil;
currentString = [[NSString alloc] initWithFormat:#"Just a Test (iPhone/iPod/iPad)." ];
picker.body = currentString;
[self presentModalViewController:picker animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];

MFMailComposeViewController displaying only bar

MFMailComposeViewController displaying only bar at the top of the screen with the cancel and send buttons. Code for landscape:
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"In app email..."];
[controller setMessageBody:#"...Hi, all...." isHTML:NO];
//[self presentModalViewController:controller animated:YES];
controller.view.frame = CGRectMake(0,0,480,320);
[self.view addSubview:controller.view];
[controller release];
What is problem?
i've ever seen this problem before, as far as i know, you shouldn't replace the presentModalViewController method with addsubview.
I was getting this behavior, as well as the modal view coming in from the side and the modal view was stopping a quarter of the way through presenting.
In my app I had many view controllers stacked with addSubview:. I don't know why but it worked to present the modal view from the bottom view controller. I did something like this:
[((FirstViewController*)[UIApplication sharedApplication].delegate).firstViewControllerInstance sendEmailwithInfo];
Hope that helps! And maybe someone can give some insite as to why it was happening.

Weird UI problem when modal view is dismissed

As shown in the screenshot below, i have a UITableView with some info and upon selecting a row an ABUnknownPersonViewController is invoked. In order to be able to able to dismiss that and go back to the UITableView I have this code:
ABUnknownPersonViewController *unknownPersonView = [[[ABUnknownPersonViewController alloc] init] autorelease];
[unknownPersonView setUnknownPersonViewDelegate:self];
[unknownPersonView setDisplayedPerson:personRecord];
[unknownPersonView setAllowsAddingToAddressBook:YES];
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Επιστροφή" style:UIBarButtonItemStylePlain
target:self action:#selector(goBackToView)];
unknownPersonView.navigationItem.title = #"Προσθήκη στις επαφές";
unknownPersonView.navigationItem.leftBarButtonItem = anotherButton;
navigationController = [[[UINavigationController alloc] initWithRootViewController:unknownPersonView] autorelease];
//navigationController = [[[UINavigationController alloc] initWithRootViewController:self] autorelease];
//self.navigationItem.rightBarButtonItem = anotherButton;
[self presentModalViewController:navigationController animated:YES];
} // didSelectRowAtIndexPath ends here
- (IBAction)goBackToView {
[self dismissModalViewControllerAnimated:YES];
}
- (void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonView didResolveToPerson:(ABRecordRef)person {
// CallerIDAppDelegate *delegate = (CallerIDAppDelegate *)[[UIApplication sharedApplication] delegate];
[navigationController dismissModalViewControllerAnimated:YES];
}
The problem (as you can see) is that when the ABUnknownPersonViewController is dismissed by the "Επιστροφή" button, which is "Back" actually, the view holding the tableView and the blue UIButton is moved a couple of pixels to the bottom!
Any help on what could be causing this?
Screenshot http://dl.getdropbox.com/u/1237004/problem.jpg
Debug this by checking your view's frame in -viewWillAppear, -viewDidAppear, -viewWillDisappear, and -viewDidDisappear.
Also check the view's autoresizingMask, and the parent view's autoresizesSubviews property.
I'm not sure I see the value of setting up a navigation controller here. You could just present the ABUnknownPersonViewController with [self presentModalViewController: unknownPersonView];. If you're doing it for the sake of picking up the visual navigation bar with the back button, then just add a nav bar and button to the unknown person view.
It seems like a mixed metaphor to be creating a UINavigationController but then not using its usual navigation methods (e.g., pushViewController:animated: and popViewControllerAnimated:) and instead using the modal methods inherited from UIViewController.
It seems that adding this line:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
in my viewWillAppear: made the view not to move when the modal view controller is dismissed. However now the initial position was already slightly dislocated to the bottom but fixed it by moving all the outles in IB to the top so it looks ok.

iphone - adding the view of MFMailComposeViewController (in-app email)

I've spent the past two days just trying to enable the sending of email from within my app. Hoping one of the smart folks on here can help me out.
presentModalViewController doesn't work for me (just crashes the app with no explanation as to why), so I'm forced to add the view of MFMailComposeViewController. Here's my attempt:
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"test subject"];
[controller setMessageBody:#"this is the message body" isHTML:NO];
// [self presentModalViewController:controller animated:YES]; //this crashes the app
//so I try this instead:
controller.view.frame = CGRectMake(0,0,480,320);
[self.view addSubview:controller.view];
[controller release];
What gets added to the screen is the subject bar only, with cancel and send buttons. None of the text fields (To:, Cc:, Subject, body) are displayed. Why aren't they a part of MFMailComposeViewController's view, and how can I display them?
Honestly, you should be using presentModalViewController. Rather than force your way around the SDK, consider debugging the crash. Turn on the debugger and see if there are any exceptions logged in the console. Check for crash logs, etc...
Also, make sure that self is a proper delegate and a UIViewController subclass.
I 've solved this problem:
try NOT this:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
but THIS:
MFMailComposeViewController *mailComposeViewController = [MFMailComposeViewController new];
You should instead try:
[[self navigationController] presentModalViewController...];
Since that's the proper way to present it. Trying to add its view manually is unfortunately utterly incorrect and will never work.
Well I have determined that one must create a dummy view controller otherwise the darn thing won't slide in.
I create a class called Sys_Mail that is a #interface Sys_Mail : UIViewController <MFMailComposeViewControllerDelegate>
and then i create basically a root view view controller. I wrestled with portrait/landscape for hours but determined that if you attach the view controller to the top level view (which contains my landscape transform) then it slides in as a landscape window. There is just one visual glitch, the parent window gets moved around for a few seconds while the new window slides in, this is a side effect of the landscape transform doing odd things to the parent....
in order to get landscape orientation on the sliding window you must declare a method in your Sys_Mail class that handles the autorotate message:
//=======================
// shouldAutorotateToInterfaceOrientation
//=======================
// see if this ever gets called for the view controller
-(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
if (TRACE) printf ("shouldAutorotateToInterfaceOrientation\n");
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); // or whatever orientation is needed
}
the variable gMasterView refers to my top level view (that has the landscape transform and is attached to the window). Subviews don't seem to work, view controllers are awful THEY ARE MORE DESIGN PATTERN CRAP. I want total control of my views not some microsoft MFC type crud!
Sys_Mail* g_root_vc;
if (g_root_vc == nil) {
// create an empty view controller so we have something to work with
g_root_vc = [[Sys_Mail alloc] init];
g_root_vc.view = (UIView*) gMasterView;
}
so this
I have the same crash and finally I can fix it by sending presentModalViewController message to [self navigationController].
Here is my code:
// Create the Mail composer view controller
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
// Set the view controller delegate
controller.mailComposeDelegate = self;
// Set recipients, if you want
[controller setToRecipients:recipients];
// Set subject, if you want
[controller setSubject:#"The subject"];
// Set message body, if you want
[controller setMessageBody:#"The message body" isHTML:YES]; // isHTML -> YES/NO depending the message body
// Present the view controller
[[self navigationController] presentModalViewController:controller animated:YES];
// Memory management
[controller release];
I hope this can help!