Search code examples
objective-cxcodeopenurl

See if another app is downloaded Xcode Objective-C


I am adding a few location to my app. I have it where it defaults opening these locations in Apple maps. But I want to make it where if the user has Google maps downloaded they will have the choice to open it in Google maps. So how do I get Xcode in Objective-c to see if the user has Google Maps on their phone? the way I use to do it doesn't seem to be working anymore.

This is What I have been using

-(IBAction)parkerMap {
{

    BOOL isAppInstalled=[[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"google.maps://"]];
    if(isAppInstalled)
    {
        UIAlertController* maps = [UIAlertController alertControllerWithTitle:@"" message:@"Would you like to open in Apple or Google Maps?"
                                                               preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction* appleAction = [UIAlertAction actionWithTitle:@"Apple" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://maps.apple.com/?address=68,D.L.WeatherlyLn.,38388"] options:@{} completionHandler:nil];
                                                         }];
        UIAlertAction* googleAction = [UIAlertAction actionWithTitle:@"Google" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com/maps/place/68+D.L.+Weatherly+Ln,+Wildersville,+TN+38388/          @35.7776813,-88.3943264,17z/data=!3m1!4b1!4m5!3m4!1s0x887c717763333487:0x8ac40c35453bbb84!8m2!3d35.777677!4d-88.3921377"] options:@{} completionHandler:nil];
                                                          }];

        [maps addAction:appleAction];
        [maps addAction:googleAction];
        [self presentViewController:maps animated:YES completion:nil];
         }
    else
    {

       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://maps.apple.com/?address=68,D.L.WeatherlyLn.,38388"] options:@{} completionHandler:nil];
    }

}
}

enter image description here


Solution

  • See here

    if ([[UIApplication sharedApplication] canOpenURL:
         [NSURL URLWithString:@"comgooglemaps://"]]) {
      [[UIApplication sharedApplication] openURL:
       [NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];
    } else {
      NSLog(@"Can't use comgooglemaps://");
    }
    

    https://developers.google.com/maps/documentation/urls/ios-urlscheme