How to send a message in iPhone devices? - iphone

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.

Related

Sending sms from phonegap in iphone?

Is it possible to send sms using phonegap in iphone??If yes can anybody suggest me sample code or tutorials to do so???
Is it possible to find out user's phone number using phonegap in iphone??If yes can anybody suggest me sample code or tutorials to do so???
If you want to send sms via phone first you should create a plugin(see phonegap website to see how its done) then in plugin code(it should be native code do it like this :
You must add MessageUI.framework to your Xcode project and include a #import <MessageUI/MessageUI.h> in your header file.
Add these delegates to your header file MFMessageComposeViewControllerDelegate & UINavigationControllerDelegate.
In your IBAction method declare instance of MFMessageComposeViewController say messageInstance to check whether your device can send text use [MFMessageComposeViewController canSendText] in if condition, it'll return Yes/No in the if condition do these:
MFMessageComposeViewController *messageInstance = [[[MFMessageComposeViewController alloc] init] autorelease];
// set body for your messageInstance
messageInstance.body = #"Hello from Shah";
// then decide the recipients for the message as:
messageInstance.recipients = [NSArray arrayWithObjects:#"12345678", #"87654321", nil];
//Set a delegate to your messageInstance as:
messageInstance.messageComposeDelegate = self;
// Then present the messageViewController
[self messageInstance animated:YES];

MFMailComposeViewController in iphone app

hii every one
can we use " MFMailComposeViewController " with out using " presentModalViewController" , i mean i need to send email with out navigating to that mail composer page
i did a test project with following code
- (IBAction)buttonPressed {
arrRecipients = [[NSMutableArray alloc]init];
[arrRecipients addObject:#"xxxxxxx#gmail.com"];
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setSubject:#"Ravikiran test mail"];
[mailController setToRecipients:arrRecipients];
[mailController setMessageBody:#"this is my test app" isHTML:YES];
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
it is sending mail but it is navigating to mail composer page & then its sending but i need to send mail just on click of the button
No, you cannot use MFMailComposeViewController to send an email without user interaction. There are probably 3rd parties libraries that let you do this, but the iOS SDK does not allow you to.
Also, you're leaking the arrRecipients array.
Best way for your needs is to have a web service which sends the data to an email id.
its always to good to inform the user in some way before sending the mail.
Thanks!

iPhone SMS Capabilities

I am using the following code within my application to create and populate a SMS for the user to send. This code is called by pressing a UIButton.
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"Hello from Mugunth";
controller.recipients = [NSArray arrayWithObjects:#"12345678", #"87654321", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
On the initial loading of the view, I would like to test the device capabilities, and hide the button if necessary (for example on an iPod touch).
Does anyone have any code examples on how to do this? Please note, I am only targeting iOS 4.0 and greater, I am aware the above code will not work on devices using earlier versions of iOS.
Regards
[MFMessageComposeViewController canSendText] will determine whether the device you are on can send text messages. I've known it to react correctly on an iPhone with SIM, an iPod Touch and the iOS Simulator. I've not tested it on e.g. an iPhone without SIM or an iPad.
You can use the below code to detect whether the device can send SMS or not:
Preferred:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"sms:"]]) {
}
or
[MFMessageComposeViewController canSendText]
Make sure you call [MFMessageComposeViewController canSendText] prior to allocating an instance of MFMessageComposeViewController. Newer versions of iOS will throw an alert informing the user that they can't send messages as soon as you instantiate MFMessageComposeViewController.

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];

Send SMS programmatically on iPhone? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How to programmatically send SMS on the iPhone?
I want to send sms programmatically.
I tried with the following code,It triggers message composer and then user needs to manually select the send button but I just want everything to be done programmatically that is even to send sms not only insert recipent number and body message.
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
controller.body = #"Hello from Dinesh";
controller.recipients = [NSArray arrayWithObjects:#"999468*****", #"91999468****", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
Help me...
Can't be done. The SDK does not allow automated SMSing, for obvious reasons—your app can ask the user to hit "Send", and that's really about it.
Here's an in App tutorial for sending SMS. Must have user consent, though, so may not be the answer you are looking for.
http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/