UIAlertView invokes the telephone - ios

See this GIF
And this is the code
-(void)goGuestInfo
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[#"label.change" localize]
message:#"d"
delegate:self
cancelButtonTitle:[#"label.cancel" localize]
otherButtonTitles:[#"label.name" localize],
[#"label.email" localize],
[#"label.phone" localize], nil];
[alertView show];
}
#pragma mark - Alertview delegate
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0: break;
case 1: [self performSegueWithIdentifier:HotelBookingGuestEditNameSegue sender:nil]; break;
case 2: [self performSegueWithIdentifier:HotelBookingGuestEditEmailSegue sender:nil]; break;
case 3: [self performSegueWithIdentifier:HotelBookingGuestEditPhoneSegue sender:nil]; break;
default: break;
}
}
It only does it when I press "name" (i.e. case 1:).
I have never experienced this before and I've used alertviews many many times. Am i missing something obvious? After I go back to the app it will do the segues as it should.

Somewhere deep down in the #imports there was/is a didClickButtonAtIndex that made a phone call.

Related

iOS: Tap cancel in Messages app to go back to app that invoked it

Our team manager has proposed the following idea: within our app, when a user taps a Send Msg button, our app opens up the Messages app. Our manager wants to tap Cancel to go back to our app (see screenshot below), instead of the top left Go back to ... shortcut in the status bar. Is that possible?
This is the picture:
UPDATE The messageComposeViewController delegate method is like this, and I see some shaking when I dismiss the message controller?:****
#pragma mark - sms delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
switch (result)
{
case MessageComposeResultCancelled:
break;
case MessageComposeResultSent:
break;
case MessageComposeResultFailed:
[LMLSendResultAlert showSuccessOrFail:0 withSuccesString:#"" andFailStr:#"短信发送失败" needPopOrdismiss:0 complete:nil];
break;
default:
break;
}
[controller dismissViewControllerAnimated:YES completion:NULL];
}
This is my viewWillAppear method:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setHidden:YES];
}
If you are opening the message editor externally, that is, you just open the default Message app (I guess this is what is happening, otherwise there wouldn't be the Back button at top left corner), unfortunately I'm not aware of any way to go back to your app when clicking the Cancel button.
However, if you are using MFMessageComposeViewController, which probably is a good idea as your users don't have to leave your app, it would be definitely possible to act accordingly when users choose to cancel.
You can take a look at Apple's doc here, which utilizes mailComposeController:didFinishWithResult:error:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
[self dismissViewControllerAnimated:YES completion:nil];
}
Following what Stephenye has said, if you use MFMessageComposeViewController the cancel button will allow you to go back to your app (you will still be in your app anyway because you present the message controller as you present any other view controller).
Here is an example:
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
[controller dismissViewControllerAnimated:YES completion:^{
case MessageComposeResultCancelled:
break;
case MessageComposeResultFailed:
[LMLSendResultAlert showSuccessOrFail:0 withSuccesString:#"" andFailStr:#"短信发送失败" needPopOrdismiss:0 complete:nil];
break;
case MessageComposeResultSent:
break;
default:
break;
}
}];
}
-(void)presentMessagerOnViewController:(UIViewController*)controller
{
if(![MFMessageComposeViewController canSendText])
{
//show error message
return;
}
NSArray *recipients = #[#"0424456654"];
NSString *defaulMessage = #"You should absolutely upvote my answer";
MFMessageComposeViewController *composer = [[MFMessageComposeViewController alloc] init];
composer.messageComposeDelegate = self;
[composer setRecipients: recipients];
[composer setBody: defaulMessage];
[self presentViewController: composer animated:YES completion: NULL];
}

UIAlertViewDelegate didDismissWIthButtonIndex getting called for 1 UIAlertView, but not the other

(iOS7, xCode 5.1) I have an app that accesses the Calendar for various purposes, and I'm trying to get all of my error messaging in place.
I have 2 UIAlertviews. Both UIAlertviews show when I need them to, but I only get a call to didDismissWIthButtonIndex for one of them. The alertview called _iCloudAlert is the one that works.
If I show the _iCloudAlert, I get a call to didDismissWIthButtonIndex when a button is clicked, but when I show _deniedAccessAlert I get no call at all. I can't even see the outermost NSLog/s.
I have <UIAlertviewDelegate> in my .h file.
Code that shows the alerts, depending on Calendar access:
// Check the authorization status of our application for Calendar
-(void)checkEventStoreAccessForCalendar
{
NSLog(#"Check Status");
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
switch (status)
{
// Update our UI if the user has granted access to their Calendar
case EKAuthorizationStatusAuthorized: [self accessGrantedForCalendar];
NSLog(#"Already granted");
break;
// Prompt the user for access to Calendar if there is no definitive answer
case EKAuthorizationStatusNotDetermined: [self requestCalendarAccess];
break;
// Display a message if the user has denied or restricted access to Calendar
case EKAuthorizationStatusDenied:
case EKAuthorizationStatusRestricted:
{
NSLog(#"already denied");
[self performSelectorOnMainThread:#selector(showDeniedAccessAlert) withObject:nil waitUntilDone:NO];
}
break;
default:
break;
}
}
Both alert view methods:
- (void)informUserAboutCloud {
_iCloudAlert = [[UIAlertView alloc]
initWithTitle: #"Important!"
message: #"If you have an iCloud account.....blah, blah, blah..."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[_iCloudAlert show];
}
- (void)showDeniedAccessAlert {
NSLog(#"Show Denied Access Alert");
_deniedAccessAlert = [[UIAlertView alloc]
initWithTitle: #"Attention!"
message: #"It looks like you've blocked access to Calendar data... Blah, Blah, Blah..."
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[_deniedAccessAlert show];
}
And here is the code used to take action on the button clicks:
- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(#"button index: %i", buttonIndex); //only logs when _iCloudAlert is shown
NSLog(#"alertview: %#", alert); //only logs when _iCloudAlert is shown
if (_iCloudAlert) {
[self checkEventStoreAccessForCalendar];
NSLog(#"check for calendar access from dismissed icloud alert...");
}
if (_deniedAccessAlert) {
NSLog(#"dismissed denied access..."); //never logged
}
}
The 2nd UIAlertView has its delegate set to nil. Change that, and it will work!

Having Problems Adding "Call" Button To iOS App

Below is the action and alert view. Why Won't This Work When The User Taps The Button?
Alert/Action
-(IBAction)myButton
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"" message:#"Call (804) 378-7120?"
delegate:self cancelButtonTitle:#"NO" otherButtonTitles:#"YES",nil];
[alert show];
[alert release];
}
What To Do With User Input
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==1)
{
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"tel://(804) 378-7120"]];
}
else
{
//Do whatever you want
}
}
As far as I remember, the index of the 1st other button is 0. So you say
if(buttonIndex==0)
{...open you URL...}
else
{
NSLog(#\"cancel\");
}
Per Apple documentation for Phone Links, the format is:
tel:1-408-555-5555
Similar to an email link, there is no //, and notice the use of hyphens, not parenthesis or space.
use this method when the user hit the YES option.
**-(void)phoneCall
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:099123456"]];
}**
Change the number 099123456 to the number what you want to call.
Hope this result useful.

Using NSRunLoop to block proceeding works on Simulator but fail on device

Here I have a UIAlertView,it appears within a NSRunLoop, i want the program proceeding blocked when it appears, after i clicked the "OK" button, the program carries on. I tried 2 methods
1.in my LBAlertView.h
#interface LBAlertView : UIAlertView <UIAlertViewDelegate>
{
BOOL isWaiting4Tap;
}
#property(nonatomic,assign) BOOL isWaiting4Tap;
- (void)showModal;
#end
in LBAlertView.m
- (void)showModal
{
isWaiting4Tap = YES;
[self show];
while (self.isWaiting4Tap)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate
distantFuture]];
}
}
in delegate place
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (alertView.tag) {
case 0:
{
self.tipView.isWaiting4Tap = 0;
[((LBSceneView*)self.delegate).theBall initBall];
}
break;
default:
break;
}
}
where tipView is object of LBAlertView.
2.in LBAlertView.m
- (void)showModal
{
[self show];
CFRunLoopRun();
}
in delegate place
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (alertView.tag) {
case 0:
{
CFRunLoopStop(CFRunLoopGetCurrent());
[((LBSceneView*)self.delegate).theBall initBall];
}
break;
default:
break;
}
}
Both methods works well on simulator but fails on device, the LBAlertView pops out over and over again, seems the program is not blocked at all, can anybody figure out why, thanks

UIAlertView doesn't open url?

I created an alert view with three buttons -"Sign Up","Donate","Cancel"- when u click on either sign up or donate, safari should open with the specific website. However when I open the app, and click any of the buttons, safari doesn't open or do anything and the buttons work as though they were different versions of the cancel button. Here is my code:
In BlahBlah.h:
#interface BlahBlah: UIViewController <UITextFieldDelegate, UIAlertViewDelegate> {
}
#end
In BlahBlah.m:
#define donate_tag 0
#import "BlahBlah.h"
#implementation BlahBlah
...
- (void) donate {
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:#"Donate"
message:#"Function doesn't work yet :(" delegate:nil cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Sign Up",#"Donate",nil];
alert2.tag = donate_tag;
[alert2 show];
[alert2 release];
}
...
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alertView.tag == donate_tag && buttonIndex == 1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
else if(alertView.tag == donate_tag && buttonIndex == 2){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.yahoo.com"]];
}
}
...
#end
You need to tell the alert who handles the actions of the buttons, that is to say, who is the "delegate" of the alert view.
Since everything related to the UIAlertView is within your "BlahBlah" view controller, after creating alert2, do something like this:
alert2.delegate = self;
or declare it in your UIAlertView instantiation:
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:#"Donate"
message:#"Function doesn't work yet :(" delegate:self
cancelButtonTitle:#"Cancel" otherButtonTitles:#"Sign Up",#"Donate",nil];

Resources