Check if Google Maps App is installed in iOS 6

I am trying to figure out how to handle the result of this code to see if Google Maps is installed in the app.

[[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]];

I am creating a UIAlertView with the option in there and if it is or isn't I wish to give the user different options.

How do I take the result of the code above and turn it into a BOOLEAN?

Thanks in advance.

Answers


The result is already of canOpenURL: a boolean:

BOOL canHandle = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps:"]];

if (canHandle) {
   // Google maps installed
} else {
   // Use Apple maps?
}

Above for iOS 9.0

Step 1. Add comgooglemaps in LSApplicationQueriesSchemes in your apps info.plist

Step 2.

BOOL isGoogleMap = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps://"]];
UIAlertView *alert;

if(isGoogleMap)
{
    alert = [[UIAlertView alloc]
             initWithTitle:@"Get Directions"
             message:@"Show Map"
             delegate:self
             cancelButtonTitle:@"Cancel"
             otherButtonTitles:@"View in Apple Maps", @"View in Google Maps", nil];
}
else
{
    alert = [[UIAlertView alloc]
             initWithTitle:@"Get Directions"
             message:@"Show Map"
             delegate:self
             cancelButtonTitle:@"Cancel"
             otherButtonTitles:@"View in Apple Maps", nil];
}
alert.tag = 1010;
[alert show];

Need Your Help

Does C++ have a package manager like npm, pip, gem, etc?

c++ macos

Just wondering the best way to install cpp packages. My background is in JS/Ruby/etc, so it seems so weird there's no cpm or the like. What am I missing? I assume it's not this simple...

Entity Framework Migrations renaming tables and columns

c# sql-server entity-framework entity-framework-5 ef-migrations

I renamed a a couple entities and their navigation properties and generated a new Migration in EF 5. As is usual with renames in EF migrations, by default it was going to drop objects and recreate ...