how to check device is not able to send SMS - iphone

I wanted to know is it possible to check that a device can send sms or not.. if my app is installed on the ipad the sms button should hide... how to do this?

try this -
if([MFMessageComposeViewController canSendText])
{
// send sms
}

BOOL canSend = [MFMessageComposeViewController canSendText];

You can try checking for UIDeviceSMSCapability in UI Device extension categories from Erica Sadun.

Related

how to open iMessage with some text message?

This is how I open iMessage in my ipad app
NSString *stringURL = #"sms:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
But what I want is open iMessage with some message i have text filed and i want to send its test to i message the way we do in mail like
[mailViewController setMessageBody:textView.text isHTML:NO];
is there anything in iMessage by which I can open iMessage with test filed Message
thanks in advance
Very late response, but this was the first result I saw when trying to solve this problem and I wanted to provide my solution.
My reason for wishing to open the iMessage app and not use MFMessageComposeViewController was because MFMessageComposeViewController does not support iMessage apps. My goal was to prompt the user to open my iMessage app and the only way to do that is to open the iMessage app.
This can be done as follows (in Swift 2):
let phoneNumber = "9765432100"
let bodyText = "Hello World"
guard let messageURL = NSURL(string: "sms:\(phoneNumber)&body=\(bodyText)") else { return }
if UIApplication.sharedApplication().canOpenURL(messageURL) {
UIApplication.sharedApplication().openURL(messageURL)
}
Some things to keep in mind:
1) You must add sms: to LSApplicationQueriesSchemes in your Info.plist
2) You can not open group messages in this manner.
3) Phone numbers must be formatted as follows: 9765432100. No spaces or extra characters, just the number
You can not open iMessage with any URL. Messages.app will detect if the number has iMessage support and sent the message via iMessage.
When calling sms: URI you are just opening any app that will handle it, on a iPhone/iPad this will be the message app. The is the given number has an iMessage account the sms will be send via the iMessage network. If no account is found on the iPad you can not send the message.
if you wan the user to send an SMS message from within your app you should use MFMessageComposeViewController.
Like:
// Fist check if we can send messages
if ([MFMessageComposeViewController canSendText] {
MFMessageComposeViewController *composer = [MFMessageComposeViewController new];
composer.body = #"Your message goes here";
// Then present the composer in a UIPopoverController.
}

MFMessageComposeViewController: How to restrict to send message as Cellular Message not as iMessage

I use MFMesageComposeViewController to send message it is creating problems for me.
when i send message to multiple recipients it works fine whether iMessages are Enable or disable from settings. But when i send message to single contact and and iMessages are enable from settings it gives me "Delivery failed" in Message App and show it as iMessage.
How can i force MFMessageComposeViewController to send it as Cellular Message.
My Code is:
[[[MFMessageComposeViewController alloc] init] autorelease];
if ([MFMessageComposeViewController canSendText]) {
controller.body = #"Sample Text Message";
controller.recipients = [NSArray arrayWithObject:#"XXXXXXXXXXXX"];
controller.messageComposeDelegate = self;
}
In short - you can't. If iMessage is enabled on a device and recipient is available as iMessage client, the message WILL be sent as iMessage. This behaviour is defined by iOS itself, you can't change it.
Apple does not provide any methods to detect whether a message is sent as 'iMessage' or 'SMS'.
Also,your message will not be send as iMessage if you are not connected to internet.If you have slow internet connect connectivity,your message will autometically be send as SMS.
If recipient is available as iMessage client and iMessage is enabled on your device then your message will be sent as iMessage. And if at that time,you are not connected to internet,then the 'send' button will be autometically disabled.

iPhone in app mail not returning to the application

I am new to iOS development. I had created an iOS application. In my app, when an email is detected , I had written code to launch the default email application in iPhone.
And upto this, it was working fine. The default iPhone compose mail interface is launching and I can send the mail.
But the problem is after sending the mail,the control is not returning back to the app.
What can I do to return the control back to my app ?
Experts please help.
Instead of launching the default email application in iPhone, use MFMailComposeViewController interface to send email.
See here for more refernce.
Dismiss the mail view in MFMailComposeViewController delegate method "didFinishWithResult"
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
All the best.

how can i send sms programmatically in iphone

I need to send sms programmatically.
I found sending programmatically email in google,But did n't found clear info regarding sending sms programmatically.
Can any one pls post some sample code.
Thank u in advance.
You can prompt the user to send a message with the number to send it to filled out, along with the body of the message, but you cannot send an SMS without the user completing the send.
Here is a perfect blog that can be used to send sms through application. SMS sending through application is introduced with iOS4.0 So you can not use MFMessageComposer in the previous versions of iPhone.
iOS 4 will be the minimum requirement.
hAPPY iCODING...
-(void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSString *str=#"Your String for SMS"
picker.body=str;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Use this and add framework MessageUI.framework and call this function whenever you want to send message

When will [MFMailComposeViewController canSendMail] return NO

My iPhone app is using the MFMailComposeViewController class to send an in-app email with an attachment.
The app will only attempt to display the mail composer dialog if the "canSendMail" method of class MFMailComposeViewController returns true (YES). Specifically, if the following method returns YES, it shows the mail composer, otherwise the user is presented with an error alert dialog stating that there are no email accounts set up on the device:
- (BOOL)canDeviceSendEmail
{
Class mailClass = (NSClassFromString(#"MFMailComposeViewController"));
return mailClass != nil && [mailClass canSendMail];
}
A team of testers have reported that they get this error alert dialog, even when email accounts are set up on the device. The tester used an iPhone 3G with OS 3.1.3. Therefore the MFMailComposeViewController class must have existed, and the "canSendMail" method must have returned NO.
My question is therefore: apart from the case when there are no email accounts set up on the device, in what other circumstances can the "canSendMail" method return NO?
~ Thanks
If at least one email account is enabled on the device, the following call should return YES:
[MFMailComposeViewController canSendMail]
Conversely, if all accounts are disabled/removed, it will return NO.
For +canSendMail to return YES the default account must be set-up for sending emails.
(Internally, +[MFMailComposeViewController canSendMail] calls +[MailAccountProxy defaultMailAccountForDelivery], which finds the first mail account being -isDefaultDeliveryAccount.)
In addition to an email account not being setup on a device, canSendMail also returns NO when an MDM profile is installed and configured to not allow third party apps to send mail. In this case you must use openURL: with a mailto: URL in order to launch Mail.app and optionally fill in the to, cc, bcc, subject, and body field.
mailto: RFC
https://www.rfc-editor.org/rfc/rfc2368
This worked for me.
In Device Go setting->Mail,Contacts,Calendar->Accounts
Here you can see no account is added.Now add account now go back to your app and you can find its returning yes this time and you are able to send E-mail.
Thanks
[MFMailComposeViewController canSendMail] will return NO when you don't have any mail account on device. In this case you can open mail app by the following code:
- (void)openMailApp {
NSString *recipients = #"mailto:?cc=&subject=";
NSString *body = #"&body=";
NSString *email = [NSString stringWithFormat:#"%#%#", recipients, body];
email = [email stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
In case of iOS 10.1, you can enable mail from iCloud first (in Settings). Then sign in to your iCloud account. All the contacts and email should be available in your simulator after those changes.
With the change, I can get true from:
MFMailComposeViewController.canSendMail()
I am using Xcode 8.1 with Swift 3.
Vladimir's answer without deprecated functions:
NSString *recipients = #"mailto:testingEmail#example.com?subject=emailsubject";
NSString *body = #"&body=body:";
NSString *email = [NSString stringWithFormat:#"%#%#", recipients, body];
email = [email stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email] options:#{} completionHandler:^(BOOL success) {
}];
You can't be certain that MFMailComposeViewController must have existed because your method doesn't discriminate between MFMailComposeViewController not existing and [MFMailComposeViewController canSendMail] returning NO.
What iPhone OS you're testing on is not relevant; what version of the iPhone SDK your application links against is what determines whether MFMailComposeViewController will be available at runtime. If you want that class, you need to build with SDK 3.0 or later.
Did you include the Messaging Framework? I had a similar issue once and it was only because I forgot to add the correct framework to the XCode project.