How to invoke call event in my Iphone application? - iphone

here is the scenario:
I have fetched the iphone contact details into my application.And i have displayed email,phone details my View controller.
Now,I want to know how to invoke call event which i click on phone number in my application?

Well you just call the tel scheme:
NSURL *phoneURL = [NSURL URLWithString:#"tel:1234564897"];
BOOL hasPhone = [[UIApplication sharedApplication] canOpenURL:phoneURL];
if (hasPhone) {
[[UIApplication sharedApplication] openURL:phoneURL];
}
Apple URL scheme Reference

NSString *phoneNumber = #"tel://1234567890"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

Try with
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://123456789"]];

Related

How populate phone number value

I want to do the following. I have an array of objects (businesses) and each business has its own details including their telephone numbers.
I know how to make a call in Objective-C but I don't know how to update the numbers dynamically. I have a Details class (.h and .m) and I have declared tel as a variable.
So to make a call I would use below as an example
-(IBAction)MakePhoneCall:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:123456"]];
}
I use a DetailViewController so I have a list of businesses that gets populated and depending on the business selected, that business object is created. So for my tel I want to do the following:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:" + detail.tel]];
But this obviously doesnt work. Can anyone please tell me how this is done?
if you're making a call from your application and you want the user back into the application after the end of the call then use telprompt: instead of tel: like below
-(IBAction)MakePhoneCall:(id)sender
{
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#",detail.tel]];
[[UIApplication sharedApplication] openURL:URL];
}
I would create a [NSString stringWithFormat], then plug that in the "URLWithString".
-(IBAction)MakePhoneCall:(id)sender
{
NSString *string = [NSString stringWithFormat:#"tel:%#", detail.tel];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string];
}
Hope that helps.

How do you make a call from your app? [duplicate]

I need to call programmatically in my app in a button click.
for that i found code like this.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:1-800-555-1212"]];
Is it work in iphone sdk 3.0 and iphone 2.0 also
Can any pls help
Thank u in advance.
Keep the phone number in a separate string.
NSString *phoneNumber = #"1-800-555-1212"; // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
NSLog(#"Phone calling...");
UIDevice *device = [UIDevice currentDevice];
NSString *cellNameStr = [NSString stringWithFormat:#"%#",self.tableCellNames[indexPath.row]];
if ([[device model] isEqualToString:#"iPhone"] ) {
NSString *phoneNumber = [#"tel://" stringByAppendingString:cellNameStr];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
} else {
UIAlertView *warning =[[UIAlertView alloc] initWithTitle:#"Note" message:#"Your device doesn't support this feature." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warning show];
}
// VKJ
The following code snippet checks if SIM card is present or not as well if the device is capable of making the call such as non-sim ios devices
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel://"]]) {
// Check if iOS Device supports phone calls
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *mnc = [carrier mobileNetworkCode];
// User will get an alert error when they will try to make a phone call in airplane mode.
if (([mnc length] == 0)) {
// Device cannot place a call at this time. SIM might be removed.
} else {
// iOS Device is capable for making calls
}
} else {
// iOS Device is not capable for making calls
}
if ( ! [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"sms:"]]) {
// iOS Device is not capable to send SMS messages.
}
Don't forget to add the CoreTelephony framework
Credit

Facebook dialog Problem in Device,Not Properly Showing in Device

I Successfully Integrate Facebook in my App.Its also working fine on simulator and Iphone,With the dialog box.
But when i install facebook official App from Itunes in my Iphone.On share function it will take my App resources to that App.with the following pages.And when I delete Facebook Official App.Its again Works fine.
Any Solution???? Thanks in advance
Comment out the following lines of code of function
- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth safariAuth:(BOOL)trySafariAuth
in Facebook.m :
UIDevice *device = [UIDevice currentDevice];
if ([device respondsToSelector:#selector(isMultitaskingSupported)] && [device isMultitaskingSupported]) {
if (tryFBAppAuth) {
NSString *scheme = kFBAppAuthURLScheme;
if (_localAppId) {
scheme = [scheme stringByAppendingString:#"2"];
}
NSString *urlPrefix = [NSString stringWithFormat:#"%#://%#", scheme, kFBAppAuthURLPath];
NSString *fbAppUrl = [FBRequest serializeURL:urlPrefix params:params];
didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
}
if (trySafariAuth && !didOpenOtherApp) {
NSString *nextUrl = [self getOwnBaseUrl];
[params setValue:nextUrl forKey:#"redirect_uri"];
NSString *fbAppUrl = [FBRequest serializeURL:loginDialogURL params:params];
didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
}
}
This will always show a dialog box to the user.

UIbutton with arguments

I want to implement a contact us page where there are few phone numbers, and i want to call the number when the user clicks on them. So i decided to create buttons with the phone number as their title.
For the button click methods i have something like this
-(IBAction)numberClicked:(id)sender;
For initiation a call i know i can use this
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phoneNumber]]];
My question is how should i modify the method so that it can take the phone number(title of te button) as argument.
Help would be appreciated.
Try
NSString *phoneNumber = [sender currentTitle];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phoneNumber]]];

(iPhone app) error: too many arguments to function 'URLWithString:'

I'm trying to format a URL string however it's saying there are too many arguments. My code is below:
-(IBAction)tweetRandom {
//NSLog(#"CALLED");
test = 100;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://twitter.com/%i", test]]; // problem line
}
Anyone know how to format the URL? Was hoping there was something by the name of URLWithFormat but it doesn't exist.
You need to use stringWithFormat: like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://twitter.com/%i", test]]];