Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 5    Views: 120

mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
01/26/14 01:33 PM (10 years ago)

BT30 - Day 22 - Confirm Dial Code

BT30 is my personal project to contribute to buzztouch: https://www.buzztouch.com/forum/thread.php?fid=2348BA49BA5737C92E3D9B5&tid=2348BA49BA5737C92E3D9B5 Day 22 - Confirm Dial Code ------------- DESCRIPTION ------------- Big thanks to SmugWimp for allowing me to post this little piece of gold. A lot of times, or most if not all, tapping the call screen will initiate the call immediatly without asking if you are sure. Here is the code to fix that. ------------- CODE ------------- When using the BT Dialer plugin (which really isn't a plugin, but part of the code) one tap and you're off and dialing... not always what the user means to do. This code will throw a confirmation dialog up before proceeding, allowing the user to cancel if hitting the button was an accident: (Replace the entire section known as "placeCallWithScreenData" and replace 'BT_appDelegate' with the correct appname_delegate) ////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// //place call displys an action sheet +(void)placeCallWithScreenData:(BT_item *)theScreenData { [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"placeCallWithScreenData nickname: "%@" itemId: %@ itemType: %@", [theScreenData itemNickname], [theScreenData itemId], [theScreenData itemType]]]; //WE WILL NOT BE HERE IF THE DEVICE IS NOT CAPABLE OF MAKING CALLS //appDelegate BT_appDelegate *appDelegate = (BT_appDelegate *)[[UIApplication sharedApplication] delegate]; if([appDelegate.rootApp.rootDevice canMakePhoneCalls] == TRUE){ //the numbe NSString *number = [BT_strings getJsonPropertyValue:theScreenData.jsonVars nameOfProperty:@"number" defaultValue:@""]; //dictionary of screen options NSString *callLabel = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"callTitle", @"Call"), number]; UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"callMessage", @"Would you like to make a phone call?") delegate:self cancelButtonTitle:nil destructiveButtonTitle:NSLocalizedString(@"callCancel", @"Do Not Call") otherButtonTitles:callLabel, nil]; [actionSheet setTag:99]; [actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque]; //how we display the action sheet depends on layout //is this a tabbed app? if([appDelegate.rootApp.tabs count] > 0){ [actionSheet showFromTabBar:[appDelegate.rootApp.rootTabBarController tabBar]]; }else{ //theNavController = [appDelegate.rootApp rootNavController]; [actionSheet showInView:[appDelegate.rootApp.rootNavController view]]; } [actionSheet release]; }else{ //show alert... UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"callsNotSupportedTitle", @"Calls Not Supported") message:NSLocalizedString(@"callsNotSupportedMessage", @"You need to be using an iPhone to make phone calls") delegate:self cancelButtonTitle:NSLocalizedString(@"ok", @"OK") otherButtonTitles:nil]; [alert show]; [alert release]; } } ////////////////////////////////////////////////////////////////////////////////////////////////// //action sheet delegate methods (action sheet is displayed for confirmations) //action sheet for call-us button click confirmation +(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"actionSheet:clickedButtonAtIndex: %i", buttonIndex]]; /* IMPORTANT. Numbers should not contain parenthesis, dashes are better. Example: 123-123-1234 is better than (123)123-1234 Not sure why but crazy results happen sometimes? */ //place phone call prompts have tag == 99 int theTag = actionSheet.tag; NSString *numberToCall = [NSString stringWithFormat:@"tel:%@", [actionSheet buttonTitleAtIndex:[actionSheet firstOtherButtonIndex]]]; //remove the word call (or whatever it is in current language) from number so the dialer works. NSString *callLabel = NSLocalizedString(@"callTitle", @"Call"); numberToCall = [numberToCall stringByReplacingOccurrencesOfString:callLabel withString:@""]; numberToCall = [numberToCall stringByReplacingOccurrencesOfString:@"(" withString:@""]; numberToCall = [numberToCall stringByReplacingOccurrencesOfString:@")" withString:@"-"]; numberToCall = [numberToCall stringByReplacingOccurrencesOfString:@" " withString:@""]; if(theTag == 99){ if(buttonIndex == 1){ [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"launching dialer: %@", numberToCall]]; if([numberToCall length] > 5){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:numberToCall]]; } }else{ //cancel clicked, do nothing } } } ---------------------------- You're done! Make sure to change YOUR APP NAME_appDelegate to (your project name)_appDelegate, all instances). Hope this helps someone - and thanks again, Smug. David.
 
Jake Chasan
Veteran developer
Profile
Posts: 1685
Reg: May 13, 2011
location unknow...
29,650
like
01/26/14 01:57 PM (10 years ago)
Thanks for Sharing. If a Buzztouch member does not know how to implement this (or does not have the time), they can use my plugin, Phone Dialer: https://www.buzztouch.com/plugins/plugin.php?pid=36034D9ADE974ED4CE7EBE9 Jake
 
chadh0130
Apple Fan
Profile
Posts: 352
Reg: Nov 05, 2011
Rhode Island
4,020
like
01/26/14 03:47 PM (10 years ago)
Works great! Thanks for the post :)
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/26/14 06:39 PM (10 years ago)
Don't thank me too much; I just found the code in a BTv1.5 post, and updated it a little… Cheers! -- Smug
 
EdReyes
Lost but trying
Profile
Posts: 574
Reg: Oct 21, 2013
location unknow...
17,640
like
01/28/14 11:58 AM (10 years ago)
Catching up on MrDavid's freebies, very useful thanks again.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
01/28/14 01:47 PM (10 years ago)
No problem :-)
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.