iPhone SDK - opening links in a UITextView in a web view

前端 未结 6 1610
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 18:00

I have specified dataDetectorTypes on a UITextView so that URLs open in Safari when touched.

Is it possible to intercept this behaviour so I load the URL in a UIWebV

6条回答
  •  醉酒成梦
    2021-01-06 18:48

    The answer above that works best is the replacement of method implementation for [UIApplication openURL:]

    Another way to achieve that, without using runtime.h is to subclass UIApplication. Then, override the openURL: selector. With this approach, you can call [super openURL:] from your subclass for URLs you want the default handling for. It also seems a little cleaner to me since you don't need to mess with the internal method implementations of the classes.

    If you choose this approach, though, there are 2 other important steps. In the main.m file you need to change the 3rd argument to the UIApplicationMain function call so that it matches the name of your subclass:

    int retVal = UIApplicationMain(argc, argv, @"MyApplicationSubclass", nil);
    

    Also, you should probably change the class of the File's Owner in your MainWindow.xib file from UIApplication to your subclass.

提交回复
热议问题