Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iPhoneSpain

macrumors newbie
Original poster
Sep 27, 2009
28
0
Hello,

I've categorized UIApplication so I can load a UIWebView when a click on links inside a UITextView. Here it is:

Code:
@implementation UIApplication (UIApplicationCategory)


- (BOOL)openURL:(NSURL*)url {
	
	
	if ([[url absoluteString] rangeOfString:@"tel://"].length==0) {
		[[self delegate] loadReviewsBrowser:url];
		return NO;


	}
	
	return YES;
	 
}
 
	 
@end

Everything works flawlessly (UIWebView-wise) but now, when I want to launch the telephone app (which is opened via the same method) nothing happens. Here's the code:

Code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://XXXXXXXXX"]];

How can I change openURL so that both cases work ok?

Thanks
 
Instead of just using a category use a subclass. Then instead of returning YES (and not doing anything else) call the implementation of openURL: in your superclass.
 
Instead of just using a category use a subclass. Then instead of returning YES (and not doing anything else) call the implementation of openURL: in your superclass.

When I implement that category, the openURL method of my category is called and I can captured the URL. Now I have this:

Code:
@interface UICustomApplication : UIApplication {

}

@end

#import "UICustomApplication.h"


@implementation UICustomApplication


- (BOOL)openURL:(NSURL*)url {
		
	
	if ([[url absoluteString] rangeOfString:@"tel://"].length==0) {
		[[self delegate] loadReviewsBrowser:url];
		return NO;
		
		
	}
	return YES;
	
}


@end

And this method is never called...

Maybe I've not understood the way yo wanted me to implement this... :(
 
1) What category. Your new code does not show any categories. It shows a subclass. Terminology is important if you want to be understood.

2) Is that all you changed? As you need to tell the system to use your new subclass (if you don't it just uses UIApplication). You should update either the main.m file or the target settings (so your info.plist). I'm not on a Mac right now so the best I can do is point you here: http://stackoverflow.com/questions/1399202
 
Thanks!

I've already figured it out! :)

It's been the first time I've subclassed UIApplication and I didn't know I had to change that in main.m ;)

Thanks again!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.