Ok so the project that I'm working on has a twitter feed that I put into a table I put the main part of the tweet in a UITextView. I want it to be able to open links in the text in a UIWebView. I managed to intercept the open url call by using the following.
#import "MyApplication.h"
#import "haydnboardAppDelegate.h"
@implementation MyApplication
- (BOOL)openURL:(NSURL *)url
{
return [self openURL:url forceOpenInSafari:NO];
}
-(BOOL)openURL: (NSURL *)url forceOpenInSafari:(BOOL)forceOpenInSafari
{
if(forceOpenInSafari)
{
// We're overriding our app trying to open this URL, so we'll let UIApplication federate this request back out
// through the normal channels. The return value states whether or not they were able to open the URL.
return [super openURL:url];
}
//
// Otherwise, we'll see if it is a request that we should let our app open.
BOOL couldWeOpenUrl = NO;
NSString* scheme = [url.scheme lowercaseString];
if([scheme compare:@"http"] == NSOrderedSame
|| [scheme compare:@"https"] == NSOrderedSame)
{
// TODO - Here you might also want to check for other conditions where you do not want your app opening URLs (e.g.
// Facebook authentication requests, OAUTH requests, etc)
// TODO - Update the cast below with the name of your AppDelegate
// Let's call the method you wrote on your AppDelegate to actually open the BrowserViewController
couldWeOpenUrl = [(haydnboardAppDelegate *)self.delegate openURL:url];
}
if(!couldWeOpenUrl)
{
return [super openURL:url];
}
else
{
return YES;
}
}
@end
I changed my main.h file as well to:
return UIApplicationMain(argc, argv, @"MyApplication", nil);
I tried to call the open url function in the code but it won't call the function at all it doesn't do anything when I click on the links in the TextView. What do I do to get it to call the function to change the view?
Edit: Managed to get the Function in my app delegate to run but when it tries to push the view controller nothing happens. I get the error viewController not in window hierarchy so I decided to change the function so that it calls a function in the viewController but still nothing happens but there is no error message when pushViewController is called in the viewController. I found that this is because the navigationController = nil how do I fix this?