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

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

Related

Send text then call Contact iPhone App

I have an emergency call app. When the user presses on the contact it calls them. Then the user has to return to the app to send the automated SMS. However I would like it that when pressed on the contact the user is taken to the message framework and once send is pressed it then calls the person. Here is the code so far.
- (NSString *)deviceLocation {
return [NSString stringWithFormat:#"Hi, you have been contacted as there has been an emergancy. Here is the location of the caller: Latitude: %f Longitude: %f . Please call for help to that location. From Kiddy Call the iPhone app. ", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude];
}
#pragma mark - PictureListMainTableCellDelegate methods
-(void)pictureListMainTableCell:(PictureListMainTableCell *)cell wantsToCallNumber:(NSString *)number
{
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *messageComposer =
[[MFMessageComposeViewController alloc] init];
NSString *message = (#"%#", [self deviceLocation]);
[messageComposer setBody:message];
messageComposer.recipients = [NSArray arrayWithObjects:number , nil];
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
NSLog(#"Texting telephone number [%#]", messageComposer);
}
NSString *urlString = [NSString stringWithFormat:#"tel://%#", number];
NSLog(#"calling telephone number [%#]", number);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
NSLog(#"%#", [self deviceLocation]);
}
Any solutions to this will be greatly appreciated.
You're doing:
messageComposer.messageComposeDelegate = self;
just define:
messageComposeViewController:didFinishWithResult
It will be called when someone finished editing text and you can get result out of second parameter.
MessageComposeResultCancelled,
MessageComposeResultSent,
MessageComposeResultFailed
And from this callback you can make a call.
To make a call use:
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:#"123123123"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
or tel:// for calling without prompting.

Twitter integration no response in (ios 5)

I am developing a application in which I have integrated Twitter by using these Twitter-Oath-iPhone.
These library are working fine on lower version then ios 5 how can I use the twitter in ios 5. I don't know either Twitter change in there API or apple have make any change in ios 5.
you used API well work in IOS 5 only minor change in "SA_OAuthTwitterEngine.m" class
Replace this Function in "SA_OAuthTwitterEngine.m" class
- (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate
{
if (self = (id) [super initWithDelegate: delegate]) {
self.requestTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/request_token"];
self.accessTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/access_token"];
self.authorizeURL = [NSURL URLWithString: #"https://twitter.com/oauth/authorize"];
}
return self;
}
Try by replace this Function in "SA_OAuthTwitterEngine.m"
- (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate {
if (self = (id) [super initWithDelegate: delegate]) {
self.requestTokenURL = [NSURL URLWithString: #"http://twitter.com/oauth/request_token"];
self.accessTokenURL = [NSURL URLWithString: #"http://twitter.com/oauth/access_token"];
self.authorizeURL = [NSURL URLWithString: #"http://twitter.com/oauth/authorize"];
}
return self;
}
in place of this code use this one
- (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate {
if (self = (id) [super initWithDelegate: delegate]) {
self.requestTokenURL = [NSURL URLWithString: #"https://api.twitter.com/oauth/request_token"];
self.accessTokenURL = [NSURL URLWithString: #"https://api.twitter.com/oauth/access_token"];
self.authorizeURL = [NSURL URLWithString: #"https://api.twitter.com/oauth/authorize"];
}
return self;
}
this one slove my problem........
Twitter integration for iOS 5 Tutorial:
One of the exciting new features in iOS 5 is Twitter integration. Photos, YouTube, Safari, and Maps come fully integrated. With most iOS 5 users jumping on the Twitter bandwagon (Twitter daily signups tripled, according to Twitter’s CEO), allowing your users to tweet about your app could help put it in front of more people. In this iDevBlogADay post, I want to write a tutorial for integrating your app with Twitter.
For twitter integration in ios 5 its very easy , because of new framework added in ios 5 onwards just follow there steps:
1. add twitter.framework
2. follow from twitter official site
There is a very easy way in ios-5 for twitter integration, just add Twitter framework and use this code. Link is below.
http://bit.ly/FLTwitter
you can also use this code with inbuilt framework of Twiiter in iOS5.....
just add Twitter.framework from your build library
and then just import bellow header file in your viewcontroller.h file
#import <Twitter/TWTweetComposeViewController.h>
afetr that when you want to share your message on twitter just use bellow code
in viewcontroller.m file again just import
#import <Twitter/TWTweetComposeViewController.h>
.....
- (IBAction)shareOnTwitter:(id)sender {
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:#"It's really that simple!"];
[twitter addImage:[UIImage imageNamed:#"yourimage.jpg"]];//if required
[twitter addURL:[NSURL URLWithString:#"your url link"]];//if required
[self presentViewController:twitter animated:YES completion:nil];
twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {
if(res == TWTweetComposeViewControllerResultDone)
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Succes!" message:#"Your Tweet was posted succesfully" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}else if(res == TWTweetComposeViewControllerResultCancelled)
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Canceled" message:#"Your Tweet was not posted" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
[self dismissModalViewControllerAnimated:YES];
};
}
May this Help you
and this code is may b not work in simulator sometime so test it in device.....

Identify device's IOS version dynamically [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Check iPhone iOS Version
I'm building an app that has an SMS composer (which isn't available in 3.0).
How can I find the underlying device's OS version dynamically and make the SMS option available, and if not disable the function.
Here is the piece of code which will give you all the info about device
NSLog(#"uniqueIdentifier: %#", [[UIDevice currentDevice] uniqueIdentifier]);
NSLog(#"name: %#", [[UIDevice currentDevice] name]);
NSLog(#"systemName: %#", [[UIDevice currentDevice] systemName]);
NSLog(#"systemVersion: %#", [[UIDevice currentDevice] systemVersion]);
NSLog(#"model: %#", [[UIDevice currentDevice] model]);
NSLog(#"localizedModel: %#", [[UIDevice currentDevice] localizedModel]);
you can get here the version number.
But i will suggest you to go with checking that the phone supports mail composer,sms or not
like
Class messageClass = (NSClassFromString(#"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass canSendText])
{
MFMessageComposeViewController *msgpicker = [[MFMessageComposeViewController alloc] init];
msgpicker.messageComposeDelegate = self;
msgpicker.recipients = [NSArray arrayWithObject:[self.productInfoArray valueForKey:#"Phone"]]; // your recipient number or self for testing
msgpicker.body = #"test from OS4";
NSLog(#"chat view array %#",[self.productInfoArray valueForKey:#"Phone"]);
[self presentModalViewController:msgpicker animated:YES];
[msgpicker release];
NSLog(#"SMS fired");
}
else { NSLog(#"chat view array %#",[self.productInfoArray valueForKey:#"Phone"]);
NSLog(#"Device not configured to send SMS.") ;
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:#"Status" message:#"Device not configured to send SMS." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"cancel",nil];
[alert show];
[alert release];
}
}
This will help to resolve your problem.
Happy Coding
Cheers................
The UIDevice class has a systemVersion property you can use to get the OS version. This'll return the version value such as 3.1 or 4.2. Guess you can use this to determine access to your SMS functionality.
#property (nonatomic, readonly, retain) NSString *systemVersion
Check out the reference for more info >
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html
I think you could use NSClassFromString(#"MFMessageComposeViewController") to see if the class is available.
(Caveat: You couldn't check for UIGestureRecognizer this way because Apple used private class with the same name. Same could be true for MFMessageComposeViewController.)

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.

How to make a call programmatically?

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