Frage

I just came to know about an awesome ios feature for UITextViews i.e UITextview dataDetectorTypes. It is really useful to display text as links.

However, I noticed one thing. When the string is a physical address, Google Map is opened which is appropriate, but in a different application.

Is there any way we can open that google map in our application and not go into default iOS application wherein map is opened? So that I can go back into my application from the map. Is there any delegate method which can control this? Right now I have to minimize the application(make it run in background) and again open it which does not looks good.

War es hilfreich?

Lösung

You should use another solution for your problem.

If you use dataDetectorTypes, the link is alway opened in built-in app firstly.

You can make your action with button and custom string as below:

  • push your text into an UIButton.

  • make your text displayed as link with NSAtributedSring as this question, use UIButton instead of UITextView:

Underline text inside uitextview

  • make action for your button when user click on it.

Good luck!

Andere Tipps

Pretty easy, you'll need to subclass UIApplication, override it's openURL: and pass the application class name to the target's main.m int main(...) like this:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, @"MyApplication", NSStringFromClass([MyAppDelegate class]));
    }
}

intercepting the urls you can return NO for maps: schemes not to launch the Maps app and handle the address in whatever way you wish.


  1. In the project create a new class subclassing UIApplication
  2. Add the following method to be overridden:

    -(BOOL)openURL:(NSURL *)url { NSLog(@"Open %@", [url absoluteString]);

    // do something if the url scheme is maps:
    return NO;
    

    }

  3. In the target's main.m file change the default int main(int argc, char *argv[]) implementation to make it to use your UIApplication class, it should look like this:

    #import < UIKit/UIKit.h> //remove the leading space to compile

    #import "LXAppDelegate.h"

    #import "LXapp.h"

    int main(int argc, char *argv[]) {

    @autoreleasepool {
        return UIApplicationMain(argc, argv, NSStringFromClass([MyUIApplication class]), NSStringFromClass([MyAppDelegate class]));
    }
    

    }

That's not for ARC (i'm never using it), refer to the UIApplicationMain documentation to understand what happens and what should be probably changed for ARC support.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top