Question

I have a Subview that has a button, when tapped opens up the map and location. There is no error in code but once I get sent to Maps and get back to my app.. It opens Maps once again. So I guess the method is being called twice. How do I stop this?

- (void)openMaps:(UITapGestureRecognizer *)tapAddress{

PFQuery *query = [PFQuery queryWithClassName:@"outfitDay"];

[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    if (!error) {

        NSURL *mapUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@", [object objectForKey:@"map"]]];

        if ([[UIApplication sharedApplication] canOpenURL:mapUrl]) {
            [[UIApplication sharedApplication] openURL:mapUrl];

        } else {

            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:nil message:@"Sin Servicio!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
        }


    }
}];
}
Was it helpful?

Solution

Have you set a breakpoint or a log in your openMaps: method to make sure it's not accidentally getting called twice?

My next guess is that your query is returning a cache then performing the network request and returning that result. By default queries shouldn't return a cache, but I've seen the Parse SDK do some weird things in the past.

Try setting the cachePolicy on your query to kPFCachePolicyNetworkOnly.

query.cachePolicy = kPFCachePolicyNetworkOnly

OTHER TIPS

Can you make sure that canOpenURL method does not also open if it can?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top