MFMailComposeViewController only populating subject - iphone

This code has been working for months now on my iPhone:
[mailComposer setMessageBody:body isHTML:NO];
x = [[UIViewController alloc] init];
[x presentViewController:mailComposer animated:YES completion:nil];
[self.view addSubview:x.view];
I've set the subject, recipient email and body. It used to work fine. But now on my iPhone I get a very similar issue to the one described here:
https://stackoverflow.com/questions/15824374/ui-toolbar-button-breaking-mail-composer-but-works-fine-with-regular-button
But I'm not using barbuttons, just a regular uibutton to trigger the mail composer.
My send button is greyed out. Only the subject is populated. When I try to edit any fields, the log window gives me "no keyboard". But when I hit cancel I get the same error:
_serviceViewControllerReady:error: Error Domain=_UIViewServiceErrorDomain Code=1 "The operation couldn’t be completed. (_UIViewServiceErrorDomain error 1.)"
Strangely the exact same code works fine on my iPad (same project, nothing different for iPad). Very strange. I don't think I even updated my iphone recently, so I don't know what could be causing this change in behavior. Would appreciate any help. Thanks.

Related

Keyboard shows then immediately hides itself when showing MFMessageComposeViewController

I am building a PhoneGap app using Cordova 2.2 for IOS. I am experiencing some bizarre behavior when calling out to a native obj-c plugin I have written to show the MFMessageComposeViewController.
The setup is very simple - I have a tap event attached to a UI element, that when pressed, will make a call to my PhoneGap plugin, pass with it a number and a text message, then show the MFMessageComposeViewController with the parameters pre-populated.
My javascript looks like this:
$(document).bind('deviceready', function(){
$(".theButton").tap(function(){
cordova.exec(function(){}, function() {}, "PhoneGapSms", "SendSms", [db.getItem("profile_sms"), db.getItem("profile_emergency")]);
});
});
And my obj-c code looks like this:
- (void)SendSms:(CDVInvokedUrlCommand*)command
{
CDVInvokedUrlCommand* myCommand = command;
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
NSString* body = [command.arguments objectAtIndex:0];
NSString* toRecipientsString = [command.arguments objectAtIndex:1];
if(body != nil)
picker.body = body;
if(toRecipientsString != nil)
[picker setRecipients:[ toRecipientsString componentsSeparatedByString:#","]];
picker.messageComposeDelegate = self;
[self.viewController presentModalViewController:picker animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[picker release];
}
So, all in all, very simple stuff.
My Problem is this:
When my iPhone is plugged into my Mac and the app is run from XCode, the Message Composer overlay appears great, with my values pre-populated. Image below demonstrating the SMS interface appears fine while plugged into XCode:
When my iPhone is unplugged from my Mac, and the app is run from the spring board, the Overlay slides up, the keyboard begins to slide up, then immediately slides down - making it impossible to type or send the message. This is what it looks like when not attached to the Mac/Xcode - the keyboard begins to slide up then immediately slides down (~ < 1 sec) leaving the following interface:
I can't for the life of me figure out what would cause the keyboard to hide when not running from XCode, but work perfectly well when it is.
Is there any way to 'force' the keyboard to display, or possibly put the whole modalviewcontroller as first responder in some form or fashion?
Any suggestions are appreciated!
Edit:
The keyboard WILL appear again if you click in the contact area
You must add MessageUI.framework to your Xcode project and include a
#import <MessageUI/MessageUI.h> in your header file.
try this code may be its helpful to you..
[self presentModalViewController:picker animated:YES];
//[self becomeFirstResponder];//try picker also instead of self
Also Refer this bellow tutorial and also check demo..
new-tutorial-developing-and-architecting-a-phonegap-application
SMSComposer
i hope this help you...
I encountered these symptoms with a Sencha Touch 2.2 and Cordova 2.6.0 setup (specifically, iOS 6+ devices).
The issue was with the web framework stealing focus away from the native SMS Composer modal, typically occurring after the first SMS Composer modal had been successfully displayed and closed.
A event.preventDefault() and event.stopPropagation() call once the event had been fired (or event.stopEvent() in Sencha land) resolved this.
Hope this helps,
-James
First: The most likely culprit, without seeing your code, is that your parent (presenting) view controller may have an action in its viewWillDisappear or viewDidDisappear that is affecting who has the "first" responder. These methods get called when presenting a view controller modally. It may be behaving differently on the simulator than the device due to timing - often really close timing conditions are different on the ARM device and the i386 processor.
Second: Does anywhere in your app register for the UIKeyboardWillShowNotification or the UIKeyboardDidShowNotification? If so, put breakpoints in the methods that are called as a result - it's possible some other controller in your view hierarchy is interfering with this one.
To answer your question...
Is there any way to 'force' the keyboard to display, or possibly put the whole modalviewcontroller as first responder in some form or fashion?
No to both. The only way to make the keyboard display is to call the becomeFirstResponder method of the input view. Since Apple doesn't expose the text view, you cannot send it messages. Setting the modalViewController as first responder would be setting the wrong object.
I found the same type of issue But Not Sure it will Solve your problem or not Just Have a Look on the Following Links :
1. http://community.phonegap.com/nitobi/topics/keyboard_is_not_triggerd_in_my_ios_build
2. https://github.com/phonegap/build/issues/31
If its not Solving your issue then you can Download the Sample code Here.
Link: https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/SMSComposer

Missing keyboard in MFMailComposeViewController

I've got this code working well for months (on iOS 5.1), but I didn't check it for a long time and now (probably iOS 6.0 issue) I've noticed that my MFMailComposeViewController doesn't show the keyboard even when focusing textfields like message body or recipients.
The strange thing is that it reacts on taps, so i can set cursor on 'To' or 'Subject' and the cursor appears, or I'm able to hold the tap to make the zooming glass pop up. But no keyboard :(
SCREENSHOT OF THIS
Here's the code I'm using:
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[self presentModalViewController:mailer animated:YES];
I've been searching a lot about this and found something that deals with
[self resignFirstResponder] or [mailer becomeFirstResponder], but it didn't work.
If I add this code before or after presenting controller
NSLog(#"mailer become %d", [mailer canBecomeFirstResponder]);
It shows 0, however, the
NSLog(#"self resign %d", [self resignFirstResponder]);
shows 1, but it was 0 too before i added the
- (BOOL)canResignFirstResponder {
return YES;
}
Docs say it should return YES by default, so it's double strange.
If I create an empty project with such code it works well, but I can't really do this because my current project is quite huge.
Any help would be appreciated, getting stuck here...
Tested both on iPhone and iOS Simulator (both deployment target 5.1 and 6.0)
Just LOL. The problem was with the
[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelStatusBar + 1]
somewhere in my app. Seems like they changed keyboard windowLevel in iOS 6, so that now it's behind. I'm quite lazy to do so, but it would be interesting to know exact windowLevel of the keyboard window :)
Be careful with that!
Thanks to everyone for helping anyway!
If you want to show the keyboard, you must take the text box from the mailer and then send the message becomeFirstResponder.
However, there is not straight forward way to do that. When you touch the box of the message, does the keyboard appear?
For others who may have come up with this keyboard issue in the MailComposer this solution worked for me:
Present the view then call "becomefirstResponder" on the same
MFMailComposeViewController in the completion method.
MFMailComposeViewController* mailCon = [[MFMailComposeViewController alloc] init];
[self presentViewController:mailCon animated:NO completion:^{
[mailCon becomeFirstResponder];
}];

In-App SMS with pre-written body limited to 40 characters

I am using the MFMessageComposeViewController to send a message within the application.
Problem:
When I send the text message to a non-iPhone (e.g. Nexus One), the message is always split into two or more text messages.
But if I sent the same message directly from the native Messages app, the message is delivered in a single message.
And then I found this recently, Actually what is happening is the message body is splitting by 40 characters and I can not figure out the situation.
What could be wrong? Is there a work around for this?
CODE:
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"This is a sample body which is containing more than 40 characters...";
controller.recipients = phnNumbersArray;
controller.messageComposeDelegate = self;
[self.view presentModalViewController:controller animated:YES];
}
[controller release];
Never tried, but possible three workaround for this.
1) Try using [NSString stringWithFormat:#"%#", myMsgBody]; I don't think it would work / resolves the issue, most probably. :P
2) See if you can send NSUTF8StringEncoding way.
3) Or the problem is at the carrier's side, nothing to do with your code.
Explanation: In your scenario I see the texts are breaking up into multiple texts. Servers at the carriers' site thinks your message is too long. That means too heavy to be sent at once. This basically means it's xxmb more than what the servers takes. To reduce that size i gave you the idea of encoding way...

Email body not displayed after sending from iPhone via code

I have couple of iPhone apps that sends an email via code.
I've noticed quite a number of emails coming in from customers where everything is populated except for the body message (i always see their signature though).
I sent a test message, using the same app from my iPhone device, and i get the message (a simple "this is a test" message).
Wondering if there are any coding that needs to occur to handle different version of iOS, or perhaps different iPhone device hardwares?
Anybody noticed this before?
I would consider the possibility that the users are accidentally pressing send on a blank email. Perhaps to eliminate this as a possibility, guard against blank messages in code, then if it still happens you'll know it's a real issue.
set all delegates properly
and use this
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSString *sub= [NSString stringWithFormat:#"The Black Sheep App: %# Specials",[[BarSplArr objectAtIndex:0]objectForKey:#"barname"]];
NSString *message=[NSString stringWithFormat:#"Check out these specials for %# on %#, %# \n\n %#",[[BarSplArr objectAtIndex:0]objectForKey:#"barname"],day,date,[[BarSplArr objectAtIndex:0]objectForKey:#"drinkspecials"] ];
[controller setSubject:sub];
[controller setMessageBody:message isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];

iPhone - MessageUI - framework not found Message

I want to be able to use the iPhones Mail.app inside my application so my users can send a share email without leaving the application. I know 3.0 made this possible.
I have added the framework properly by ctrl clicking on my frameworks folder -> add existing framework.
Added this to the header file of the viewcontroller I want the Mail.app to appear in.
#import <MessageUI/MessageUI.h>
I pop up a UIAlert and on closing I call the function below, There are no errors showing up in my code. Do I have to do something extra inside the Interface Builder? Error Msg is Below
-(void)showEmailModalView {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the user did with your email sheet
NSString * emailSubject = [[NSString alloc] initWithFormat:#"iPhone Subject Test"];
[picker setSubject:emailSubject];
NSString * content = [[NSString alloc] initWithFormat:#"iPhone Email Content"];
// Fill out the email body text
NSString *pageLink = #"http://mugunthkumar.com/mygreatapp"; // replace it with yours
NSString *iTunesLink = #"http://link-to-mygreatapp"; // replate it with yours
NSString *emailBody =
[NSString stringWithFormat:#"%#\n\n<h3>Sent from <a href = '%#'>MyGreatApp</a> on iPhone. <a href = '%#'>Download</a> yours from AppStore now!</h3>", content, pageLink, iTunesLink];
[picker setMessageBody:emailBody isHTML:YES]; // depends. Mostly YES, unless you want to send it as plain text (boring)
picker.navigationBar.barStyle = UIBarStyleBlack; // choose your style, unfortunately, Translucent colors behave quirky.
[self presentModalViewController:picker animated:YES];
[picker release];
[content release];
[emailSubject release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
My ERROR MESSAGE:
ld: framework not found Message
collect2: ld returned 1 exit status
I followed this tutorial:
http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/
After doing some research I found out that the tutorial I was using was perfectly fine! The code had no errors and my problem was the way I added the MessageUI Framework to my project.
Wrong Way.
Ctrl-click on the frameworks folder and select add -> existing frameworks..
Correct Way.
Open up "targets" in the file panel on the left of your xcode screen, double click your project name. A new window will pop open, at the bottom of the new window you can add a new linked library, add one by clicking the little plus sign in the bottom left hand corner. Scroll down to MessageUI and select Add.
If you had already added the MessageUI Framework the wrong way, just simply delete it and proceed with the correct way. If it still doesn't work try shutting down xcode, restarting, and rebuilding your application.
After many hours of searching for an answer this is what worked for me.
The linker command line output will tell you a lot about what XCode is using to try and build your binary, including Framework include paths and the frameworks the linker is including in the build. From there you'll be able to see exactly what XCode is using and what might be missing from your settings. The command line output can be found in one of the output panes in the Build Results window.