Make calls from iPhone app [duplicate] - iphone

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
make a call in iphone from my application
I want to make a phone call on given number from my iPhone application. Could you suggest any good tutorial which explains it the best or tell me the process?

You can try :
NSURL *phoneNumberURL = [NSURL URLWithString:#"tel:80001212"];
[[UIApplication sharedApplication] openURL:phoneNumberURL];

NSString* phoneNumber=TextFiled Name
NSString *number = [NSString stringWithFormat:#"%#",phoneNumber];
NSURL* callUrl=[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#",number]];
//check Call Function available only in iphone
if([[UIApplication sharedApplication] canOpenURL:callUrl])
{
[[UIApplication sharedApplication] openURL:callUrl];
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"ALERT" message:#"This function is only available on the iPhone" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}

Try this:-
NSString *phoneNumber = #"15555551212";
NSString *dtmfAfterPickup = #"1234";
NSString *telString = [NSString stringWithFormat:#"tel:%#,%#", phoneNumber, dtmfAfterPickup];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telString]];

Opening an app from within another app is managed in iOS through the "url scheme" mechanism. If an app defines an url scheme, and this scheme is public, you can then use it to run that app.
Basic rule is to first check that your device supports that scheme (e.g. you cannot make a phone call on an iPad because the phone app is not installed) and then, if the answer is positive, call it:
if([[UIApplication sharedApplication] canOpenURL:myURL]) {
[[UIApplication sharedApplication] openURL:myURL];
} else {
// do something else, e.g. inform the user that he/she cannot open the app
}
This check is important as for some schemes, e.g. the phone one, the system checks is the url is well formed or not. E.g.: for phone numbers space between digits is not supported.
The most common Apple URL schemes are described here:
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1
In particular, the telephone url scheme is here:
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1
Finally there is a web site, called handleOpenURL that is trying to collect all apps url schemes. If you define an app that exposes an url scheme and you want it to be public, don't hesitate to post it in this site.

There are two ways to acheive this:-
1) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://9912345678"]];
2) You can use the UITextView and enable phone detection. After that the phone number will look like hyperlinked. Use the following code.
mytextview.text = #"9943586256";
mytextview.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
mytextview.editable=NO;
Helpful if you want to show the phone number inside a custom tableview cell.
I would personally like the second one due to requirements in some project. When i have give the telephone number in UITextView and upon pressing that will start the calling.

Related

Make phone call on iPhone and take user back to app? (UIWebView does it)

I used this code to make phone call:
NSString *phoneNumber = [#"tel://" stringByAppendingString:mymobileNO.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
and when the call ends, it does not take user back to the app. However, if I show a website in UIWebView and there is a phone number in the website(ie UIWebView recognises it), and if I tap that phone number link to make phone call, I will be taken back to the app when the call finishes.
My preliminary thinking is that the UIWebView does something internally like a deep link to the Phone app then another deep link inside the deep link to take the user back to the app. But I'm not sure. Is there a way to implement this feature?
Thanks!
You need to use the telprompt URL, not tel.
So:
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:mymobileNO.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
This will also give the user a confirmation box before calling the number.
Edit:
This question covers the same issue.
Edit 2:
For those wondering if this URL will result in rejection from the App Store, the answer is generally no. The greater risk is that Apple will suddenly stop supporting the telprompt scheme. As explained by this article, there is a slightly 'safer' way of implementing telprompt with UIWebView (which uses telprompt internally, even if you call it with tel). The relevant code from the article shows how using the documented tel scheme can still give you the effect of telprompt:
+ (void)callWithString:(NSString *)phoneString {
[self callWithURL:[NSURL URLWithString:[NSString
stringWithFormat:#"tel:%#",phoneString]]];
}
+ (void)callWithURL:(NSURL *)url {
static UIWebView *webView = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
webView = [UIWebView new];
});
[webView loadRequest:[NSURLRequest requestWithURL:url]];
}
(Code taken from the article reference in my second edit)
The website: http://www.raizlabs.com/dev/2014/04/getting-the-best-behavior-from-phone-call-requests-using-tel-in-an-ios-app/ has a discussion of whether to use telprompt (undocumented, Apple could potentially change the API without notice), and instead using a category that sends the number to a web view which opens it using telprompt. This has the advantage of not breaking if Apple does something odd.

How to return to my iphone application after call ends?

I am able to call from my iphone application by using below code:
NSString *phoneNumber = #"tel://1234567890";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Now, i want to know how to return to my application back when the call ends ?
UIWebView *phoneCallWebview = [[UIWebView alloc] init];
// [self.view addSubview:phoneCallWebview];
NSURL *callURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", 9238928399]];
[phoneCallWebview loadRequest:[NSURLRequest requestWithURL:callURL ]];
As far as I'm aware, such interaction is impossible since your application has been demoted to background, and all UI interaction has been delegated to the Phone app, and the user.
I found this SO question
End call, don't return to app automatic in iphone 3.1 version
Which pointed to an article on apple dev forums
https://devforums.apple.com/message/128046 (dev account required)
Which says it was a change in iOS 3.1 but a "workaround" is
use UIWebView to open the tel: url, after the call, your app will relaunch, but you get the annoying do you want to make this call alert.
I have't verified this works as described, just thought I'd point it out
From iOS 5, use below...
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:#"12345678"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Just use telprompt:// instead of tel://
telprompt will prompt the user first, and when call ends,it will go back to your application.
NSString *myNumber = [#"telprompt://" stringByAppendingString:txtMobileNo.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:myNumber]];

iOS: Connect to Facebook without leaving the app for authorization

I know that it was possible before the Graph API.
I work on an iPhone app that may not be in the background (one of the requirements).
In addition there is a login screen on the app launching.
Therefore it is not suitable to go to background in order to authenticate to Facebook and then return to the app and login once again each time the user wants to share something.
So, my question is if there is a way to authenticate with Facebook without leaving the app.
BTW, I have tried to use the old API.
It worked in the beginning but yesterday it stopped working.
I just see a blank screen inside the old Facebook login web view.
I have also checked one of my old apps that use that old Facebook Connect API and I get the same blank login screen in that app too.
Any idea will be appreciated.
Thank you in advance.
--
Michael.
In Facebook.m
- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
safariAuth:(BOOL)trySafariAuth {
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_appId, #"client_id",
#"user_agent", #"type",
kRedirectURL, #"redirect_uri",
#"touch", #"display",
kSDKVersion, #"sdk",
nil];
method comment out this
UIDevice *device = [UIDevice currentDevice];
if ([device respondsToSelector:#selector(isMultitaskingSupported)] && [device isMultitaskingSupported]) {
if (tryFBAppAuth) {
NSString *fbAppUrl = [FBRequest serializeURL:kFBAppAuthURL params:params];
didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
}
if (trySafariAuth && !didOpenOtherApp) {
NSString *nextUrl = [NSString stringWithFormat:#"fb%#://authorize", _appId];
[params setValue:nextUrl forKey:#"redirect_uri"];
NSString *fbAppUrl = [FBRequest serializeURL:loginDialogURL params:params];
didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
}
}
This will prevent the app from going to background and show you the standard fb dialog.
Here you have an alternative solution.
If you don't like to change the facebook sdk code and want a solution that allows you to choose between SSO or the old-fashioned mechanism, you can Implement an extension like this:
//Facebook_SSOExtension.h
--------------------------------------------------------
#interface Facebook(SSOExtension)
-(void) authorize:(NSArray*)permissions useSSO:(BOOL) useSSO;
#end
//Facebook_SSOExtension.m
--------------------------------------------------------
//So warnings do not appear
#interface Facebook(PrivateSSOExtension)
- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
safariAuth:(BOOL)trySafariAuth;
-(void) setPermissions:(NSArray*) permissions;
#end
#implementation Facebook(SSOExtension)
-(void) authorize:(NSArray*)permissions useSSO:(BOOL) useSSO
{
[self setPermissions: permissions];
[self authorizeWithFBAppAuth:useSSO safariAuth:useSSO];
}
#end
Even though this requires more work than commenting-out the sso code, you will be able to update the facebook-sdk without major problems (if they rename authorizeWithFBAppAuth:safariAuth: your extension will not work, use asserts to detect this issue quickly). Also, if you are building a reusable component to interact with facebook without repeating things over and over again, this will save you some work too.
Cheers.

how do i launch the iphone sms text application in objective-c via the sms: url scheme?

I have a button in my obj-c application that I would like to launch the iphone text application when a button is pressed.
i've looked at the solution here How to use iPhone Custom URL schemes and have attached an action to my button (via the 'touch up inside' event), but the text app doesn't launch when the button is pressed.
here is my code
(IBAction)sendMsgBtnPressed:(id)sender {
NSLog(#"sendMsgBtnPressed");
NSString *stringURL = #"sms:+14155551212";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
[stringURL release];
}
i know this is being called because i can see the NSLog() output in my console. When I use a http:// scheme it works fine & launches Safari but sms: does not appear to work. Any idea what I am missing here?
Try removing the leading plus sign before the numbers in your url. The plus sign is used for international numbers and you can safely replace it with two leading zeroes. Moreover, be sure to provide a string in which no space occurs between numbers: something like
NSString *stringURL = #"sms:00141555 51212"; will NOT work correctly.
One more thing. The statement
[stringURL release];
is not correct because stringURL has not being retained. You should remove it from your method.
Notice that the SMS application will be opened ONLY in iPhone device - not simulator and not iPod Touch.
The SMS application doesn't exist on simulator and iPod Touch...
You can also check if the device can invoke the SMS app with
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:stringURL]]

i want to send the mail from iphone within my application

I am using the following code to send the mail but when i click on the send button, it come out of the app and send the mail.
i dont want to come out of my application.
-(IBAction) done:(id) sender
{
[self sendEmailTo: #"uttam.beldar#yahoo.com" withSubject: #" Question"
withBody:[textbody text]];
}
- (void) sendEmailTo:(NSString *)to withSubject:(NSString *) subject withBody:(NSString *)body
{
NSString *mailString = [NSString stringWithFormat:#"mailto:?to=%#&subject=%#&body=%#",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
}
can any one have the solution for this ?
You probably want to look into MFMailComposeViewController - it's the best option for that after the release of iPhone OS 3.0 software.
If you don't want a UI, you need to implement the SMTP protocol, since I don't think there's a built in one. But there is a google code project that provides this, if you want to incorporate it in your app.
You can implement send mail in this easy way.
Tell me if you have problems.
A