UIbutton with arguments - iphone

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]]];

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.

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.

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 to invoke call event in my Iphone application?

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"]];

(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]]];