Send text then call Contact iPhone App - iphone

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.

Related

Sending SMS to dynamic Telephone number

I have an app which sends an sms and then calls a dynamic telephone number, here is the code:
#pragma mark - PictureListMainTableCellDelegate methods
-(void)pictureListMainTableCell:(PictureListMainTableCell *)cell wantsToCallNumber:(NSString *)number
{
MFMessageComposeViewController *messageComposer =
[[MFMessageComposeViewController alloc] init];
NSString *message = #"Your Message here";
[messageComposer setBody:message];
messageComposer.recipients = [NSArray arrayWithObjects:#"0003233", 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]);
}
the telephone call works but not the sms, can anyone help?
First check if your device can send SMS messages by:
if ( [MFMessageComposeViewController canSendText] ) {
// build your text message like you posted
}
else {
// handle appropriately
// no point in trying to display the compose view controller
}
Whether this solves your specific problem, I am not sure, since I am just following Apple's docs for this.
just replace this line in your method and you'll be able to send dynamic messages
messageComposer.recipients = [NSArray arrayWithObjects:number,nil];
and you can send emails and messages automatically without pressing send button but in that case there is a chance of rejecting of your app from the apple app store as it is not under their legal process so they'll reject your application.
and you should check condition for
if([MFMessageComposeViewController canSendText])
otherwise in iPad and iPod your application might meet crash.

iPhone SMS Url Scheme with Body Content?

I am looking to pre-fill the SMS body with content given "smsto:555-555-5555:Hello World"
I have done my research and everybody says it cannot be done but I have a QR reader on my phone right now that can take "sms:555-555-5555:Hello world" and pre-fills the content with the correct phone number scanned.
So my question is. How do i do this? it is pretty clear that the URL scheme provided doesn't handle the body. What other methods are out there to pre-fill the body? it can clearly be done with the QuickMark Reader.
You can use the modalViewController for SMS to fill the body of a text.
add the MessageUI framework to your project.
set you viewController as the MFMessageComposeDelegate
Create the modal view and present it:
-(void) showMessageComposerWithText:(NSString*)messageText telNumber:(NSString*)telNumber composeDelegate:(id)delegate
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = delegate;
[delegate presentModalViewController:controller animated:YES];
}
}
You can't launch the Messages app with a predefined message according to Apple Documentation.
What you can do is implement the handling yourself and parse the URL like the following:
NSURL *url = /* the url you get from the web (in webview delegate) or after QR Code scan */;
if ([url.scheme isEqualToString:#"sms"]) // is it a sms ?
{
if([MFMessageComposeViewController canSendText]) // can I send text message ?
{
NSArray *parts = [url.absoluteString componentsSeparatedByString:#":"];
NSString *messageText = parts.count == 3 ? [parts objectAtIndex:2] : #"";
NSString *telNumber = parts.count >= 2 ? [parts objectAtIndex:1] : #"";
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}
}
And voilĂ  !

grab text from NSMutableArray tableview cell

I don't understand why the code isn't working, and nothing I found seems to be working. So I've come here for help. Ultimately, I want to be able to send my link to Safari whenever I click on the "View" button, and I want the link to be copied whenever I click on the "Copy" button.
Here's the code (under " - (void)viewDidLoad "):
NSMutableArray *sites = [[NSMutableArray alloc] initWithObjects:#"http://www.apple.com/", #"http://www.youtube.com/", #"http://maps.google.com/", #"http://ww.google.com/", #"http://www.stackoverflow.com/", nil];
self.cloudsendList = sites;
Here is the code (under " - (IBAction) touchUpInsideAction:(UIButton*)button "):
NSIndexPath* indexPath = [tableView indexPathForCell:sideSwipeCell];
NSUInteger index = [buttons indexOfObject:button];
NSDictionary* buttonInfo = [buttonData objectAtIndex:index];
if ([[buttonInfo objectForKey:#"title"] isEqualToString:#"View"]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: #"%#", indexPath.row]]];
} else if ([[buttonInfo objectForKey:#"title"]isEqualToString:#"Copy"]) {
NSString *message = indexPath.row;
[UIPasteboard generalPasteboard].string = message;
Just to note, I am able to see the NSMutableArray data on each cell, I just can't grab it. I've also tried to insert "cloudsendList indexPath.row" instead of just "indexPath.row", but it didn't work. I hope this gives you enough information, and any bit of help would be really appreciated. Also, I apologize if I sound kind of noobish; I'm still sort of new to Objective-C programming. Thanks! :)
indexPath.row is an NSInteger, not the text at that location. This means your NSString *message is getting the integer value of the row you are on (0, 1, 2...). Try using that location as an index when pulling from your sites/cloudsendList array.
Ex.
NSString *message = [cloudsendList objectAtIndex:indexPath.row];
UPDATE:
To open the browser, use the same concept.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: #"%#", [cloudsendList objectAtIndex:indexPath.row]]]];

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

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