how to make a call in iphone? [duplicate] - iphone

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to make a call programmatically?
In my App, I have one view in which complete address along with phone number of a company gets displayed. What i want is, when a user touches that phone number, it should make a call..
So, how to do it, when user touches that phone number.
Any answer will be appriciated. Thank you guys.

If you put the text in a UITextView there is a setting for it to automatically detect phone numbers. The OS will then highlight the phone number, and if the user taps on it, it will prompt them if they wish to call that number

-(IBAction)callPhone:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:1234567890"]];
}
Then connect TouchUpInside to this and you are good to go. Hope that helps!

-(void)callPhone:(id)sender{
NSURL *url = [NSURL URLWithString: #"tel://848444488"];
NSLog(#"Call %#", url);
[[UIApplication sharedApplication] openURL:url];
}
if the phone is in the form 848 44 44 88 use this code to eliminate spaces:
NSString *phoneWithoutSpaces = [[NSString stringWithFormat:#"tel://%#", #"848 44 44 88"] stringByReplacingOccurrencesOfString:#" " withString:#""];
NSURL *url = [NSURL URLWithString:phoneWithoutSpaces];

Do this
NSString *phoneNumber = [NSString StringWithFormat:#"tel:%#", textField.text];
[[UIApplication SharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

Related

Calling other facetime emails in iOS

I would like to call other facetime numbers, but these are emails and not numbers. How do I do it?
For numbers, I know what to use.
NSURL *url = [NSURL URLWithString:#"facetime://+123456789"];
[[UIApplication sharedApplication] openURL:url];
But for emails, how do i change it. Any idea?
NSURL *url = [NSURL URLWithString:#"facetime://email#example.com"];
[[UIApplication sharedApplication] openURL:url];
These are the options
#"facetime://appleId" // For apple id
#"facetime://email#example.com" // For email id
#"facetime://5558675309" // For phone number

iPhone 4 problems dialing from inside app

There is an iOS 5.0+ app, released in App Store, which displays employees profiles with their phone numbers. The users of the app can tap on the phone number and the number will be dialed on their iPhones.
The problem is that some users with iPhone 4 are reporting that it does NOT dial.
This is the code I am using to dial:
NSString *cleanedString = [[self.member.phone componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:#"0123456789-+()"] invertedSet]] componentsJoinedByString:#""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *urlText = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#", escapedPhoneNumber]];
[[UIApplication sharedApplication] openURL:urlText];
Any ideas about this?
There shouldn't be any / in the tel: scheme:
NSURL *urlText = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", escapedPhoneNumber]];
In the Apple URL Scheme Reference you can see some example for what is allowed in the tel: scheme.
If you use telpromt instead of tel this will return you to app after your call ends|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt:1234567890"]];

How to open iphone mail application from my own application?

i am working on signup feature. In this feature when the user create account successfully. i am asking him or her to activate his account.
i want to open the mail application of iphone if user say yes.
now my question is simple how to open mail application from my own application?
#define URLEMail #"mailto:sb#sw.com?subject=title&body=content"
NSString *url = [URLEMail stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
Try this out.
-(void)launchMailAppOnDevice
{
NSString *recipients = #"mailto:myemail#gmail.com?subject=subjecthere";
NSString *body = #"&body=bodyHere";
NSString *email = [NSString stringWithFormat:#"%#%#", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
stringByAddingPercentEscapesUsingEncoding and openURL are deprecated.
Now use this:
#define URLEMail #"mailto:sb#sw.com?subject=title&body=content"
NSString * encodedString = [URLEMail stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString: encodedString] options:#{} completionHandler:nil];
Ahoy!
The long and short of it is; you can't.
You can create an email compose view for the purpose of sending emails (see MFMailComposeViewController), but you cannot open applications arbitrarily without a purpose.
See this previous post for clarification: Launch an app from within another (iPhone)
Really though, it's not much effort for the user to close your app and open Mail so I wouldn't worry too much about it anyway.

How to call a phone from a number entered in a UITextField?

I'd like to make a button call a phone number entered by the user inside the text field. I have a code but it doesn't work.
NSString * phoneNumber = [NSString stringWithFormat:#"%#%#", #"tel://", phoneNumber.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Anyone has a similar approach to this? Thanks.
I think it's tel: instead of tel://. See this Apple document. Try giving this a shot:
NSString *pn = [#"tel:" stringByAppendingString:phoneNumber.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:pn]];
See my answer to another question for some sample code to handle cases with invalid input.
Basically you do this:
NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:#"0123456789-+()"] invertedSet]] componentsJoinedByString:#""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#", escapedPhoneNumber]];
Update: I noticed that the string you created shares the some name ("phoneNumber") as the text field from which you try to get the text. You may want to rename either of those two.

sending message to pre configured numbers

Hai
I am developing a new application. In that send a message to pre configured numbers and the user selecting numbers. How it is possible? when then send button is pressed. Please help. Can any give me some Sample code or tutorial.
Thank You
Please read the below SO post,
How to send SMS and number from contacts?
Here is link could help you ...
http://iosdevelopertips.com/cocoa/launching-other-apps-within-an-iphone-application.html
SMS
To open the SMS application, just use the sms: protocol in your URL:
NSString *stringURL = #"sms:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
You can specify a phone number, but apparently not a default text for your message:
NSString *stringURL = #"sms:+12345678901";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];