Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone uialertview don';不要采取行动_Iphone_Ios_Uialertview - Fatal编程技术网

Iphone uialertview don';不要采取行动

Iphone uialertview don';不要采取行动,iphone,ios,uialertview,Iphone,Ios,Uialertview,我必须用这两个按钮设置一个警报视图,但是按钮不能打开URL。我不知道这个错误。请帮忙 代码如下: -(IBAction)showAlertView { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Obrir en..." message:@"Es pot requirir la aplicació de Google Maps"

我必须用这两个按钮设置一个警报视图,但是按钮不能打开URL。我不知道这个错误。请帮忙

代码如下:

-(IBAction)showAlertView {
UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle:@"Obrir en..."
                      message:@"Es pot requirir la aplicació de Google Maps"
                      delegate:self
                      cancelButtonTitle:@"Millor no..."
                      otherButtonTitles:@"Mapes",@"Google Maps",nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

if([title isEqualToString:@"Mapes"])
{
    UIApplication *ourApplication = [UIApplication sharedApplication];
    NSString *ourPath = @"http://maps.apple.com/?q=Plaça+del+Rei+43003+Tarragona";
    NSURL *ourURL = [NSURL URLWithString:ourPath];
    [ourApplication openURL:ourURL];

}
if([title isEqualToString:@"Google Maps"])
{
    UIApplication *ourApplication = [UIApplication sharedApplication];
    NSString *ourPath = @"comgooglemaps://?daddr=Plaça+del+Rei+43003+Tarragona&directionsmode=walking";
    NSURL *ourURL = [NSURL URLWithString:ourPath];
    [ourApplication openURL:ourURL];
}
    }
它是
UIAlertView
的委托方法,此方法用于与
UIAlertView

例如:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
  if(buttonIndex == 1)
  {
      /// write code for button 1 of UIAlertView; (here put 1 URL)
  }
  else if(buttonIndex == 2)
  {
    /// write code for button 2 of UIAlertView; (here put 2 URL)
  }
}

那么,为什么要使用两个UIAlertView作为两个URL,将URL放在
UIAlertView

的委托方法中单击的按钮的单独块中,我认为您的发送URL是错误的

应该是

maps.google.com//?daddr=Plaça+del+Rei+43003+Tarragona&directionsmode=walking
反而

comgooglemaps://?daddr=Plaça+del+Rei+43003+Tarragona&directionsmode=walking

您必须对url字符串进行url编码,因为它包含一些特殊字符

NSString *ourPath = @"http://maps.apple.com/?q=Plaça+del+Rei+43003+Tarragona";
ourPath=[ourPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

第二个UIALERTVIEW没有打开URL。你能理解我吗?这是在你的模拟器或设备上吗?如果你在谷歌地图里面放一个断点,它会停在那里吗?我认为您也应该尝试canOpenUrl:,作为一个测试,就像@rmrahul建议的那样。我有两个视图,每个视图都必须使用两个按钮放置一个警报视图,但在第二个视图中,不要打开url。我认为这是正确的,看这个:然后您需要首先检查[[UIApplication sharedApplication]canOpenUrl:[NSURL URLWithString:@“谷歌地图://”]];什么是特殊字符?在这个url中,特殊的单词是Plaça(ç特殊字符)
NSString *ourPath = @"http://maps.apple.com/?q=Plaça+del+Rei+43003+Tarragona";
ourPath=[ourPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *enc = [match.location stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSString *location = [NSString stringWithFormat:@"%@%@", @"http://maps.google.com/maps?q=",enc];
NSLog(@"%@", location);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:location]];