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...
Related
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.
Currently i am working in iPhone application, Using MFMessageComposeViewController to develop this application and its working fine.
But i want, message compose screen don't show on the screen, then the Message send programmatically ,
How to do this? it is possible? please help me
I tried this:
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"Hi";
controller.recipients = [NSArray arrayWithObjects:#"12345678", #"87654321", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
I've tried to do this once but but it wont be accepted by app store. Apple wont let you send message/email without user knowledge about it.
You can use a sms:[target phone number] URL to open the SMS application, but there are no indications on how to prefill a SMS body with text (see this post on Apple Developer Forums).
You can't use the Message Framework to send a message without the user knowing about it. One common solution is to send the message details to a web service running on your server and send the message from the server. As long as you're not trying to be sneaky, I don't think there's anything wrong with doing that.
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];
I'm working on an iPhone app that offers the user the opportunity to send an e-mail in 3 different places in the app, and for 3 different purposes.
Rather than put the same code for showing the e-mail composer in 3 different view controllers, shouldn't I develop a separate E-mail class, create an instance, and then set properties such as To, CC, BCC, Body, HTML_Or_Not, and so on?
Also, if I create an instance of such a class, and it brings up the e-mail composer, is it OK to release the class even before the e-mail composer has left the screen?
My advice, It's so easy to use the built in mail picker class, just stick with it, you can create a function to setup and show the picker, and use that when you need to like so:
- (void)showMailPicker {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
picker.navigationBar.barStyle = UIBarStyleBlack;
[picker setToRecipients: ...];
[picker setSubject:#"Title"];
// Fill out the email body text
NSString *emailBody = #"email Body...";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
Yes, it's safe to release the picker once you have presented it, and remember that once you present the picker, you can't change the email addresses, subject, body etc...
My aproach would me to encapsulate the whole process of creating, initialising, displaying, dismissing and handling all of the aspects of the mail composer in a class, like a "mail manager" or something.
Then you can create and instance and set the properties you need, and then call "show mail composer" or something to that effect.
I wouldn't recommend releasing this manager class if it will be dealing with the dismissal and handling of the result of the mail composer (ie, handling an error when sending) until after it has finished what it's doing. If you release it too early, you may not have any logical way to dismiss the mail composer or gracefully handle it's results etc.
I'm using MFMailComposeViewController to send a file. Everything works fine with files under 15mb. Anything over, and the file simply doesn't get attached to the MFMailComposeViewController view. It's not that the email server isn't accepting, its that it never gets attached in the first place.
Does anyone have any ideas if there's a way to resolve that?
I know many email services can't handle attachments over 5 or 10mb, but other services allow you much larger file size.
MFMailComposeViewController *mail = [[[MFMailComposeViewController alloc] init] autorelease];
mail.mailComposeDelegate = self;
NSString* path = [NSString stringWithFormat:#"%#/%#/%#", NSHomeDirectory(), #"Documents", fileName];
NSData *data = [NSData dataWithContentsOfMappedFile:path]; //also tried dataWithContentsOfFile with same results
[mail addAttachmentData:data mimeType:#"audio/x-caf" fileName:[NSString stringWithFormat:#"%#.caf", label]];
[appDelegate.tabBarController presentModalViewController:mail animated:YES];
Loading a 15 MB anything into RAM on a pre-2009 iPhone or iPod is going to really push the limits of your process's available memory, so it's not surprising there's a cap. I wouldn't try to convince the compose view to accept a larger attachment; instead, I'd suggest you transfer the file to some external server and either e-mail a link to it or send the mail from there.
Currently it has a 21mb limit (relevant to iOS 15). But I could sent at least 24mb when pressed Try. 25mb couldn't be attached and MFMailComposeViewController was closed by system at all.