SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
07/23/13 09:34 PM (12 years ago)

Confirm Dialing before Dial 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 } } } ////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// For the most part, it's the same version as this, but with a little housekeeping for iOS6. http://www.buzztouch.com/forum/thread.php?tid=F201A522DB008CE87F39E79&currentPage=74 And if anyone knows how to set the delegate correctly I'd appreciate your letting me know. using 'nil' renders it inoperable. anything else garners a warning. So far, only 'self' seems to work, although it's a warning. Cheers! -- Smug
 
farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
like
07/24/13 02:07 AM (12 years ago)
That's great Smug!! I always add a buffer button screen before dialing (are you sure you want to dial yes/no) but this is much better. THanks! Farcat
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
07/24/13 04:37 AM (12 years ago)
Thanks @smugwimp, I've always found myself jumping for the cancel button when I use this feature before, now I won't have to.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
07/24/13 09:20 AM (12 years ago)
Super Smug! David
 
WolfTimJ
buzztouch Evangelist
Profile
Posts: 810
Reg: Feb 20, 2011
Rockwall, TX
17,400
like
07/24/13 01:11 PM (12 years ago)
Smug, You're awesome. BT 1.4 did this, always wanted to get it back. Thanks a lot!!! Tim
 

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.