UIApplication openURL

Discussion in 'iOS Programming' started by iPhoneSpain, Apr 19, 2010.

  1. iPhoneSpain macrumors newbie

    Joined:
    Sep 27, 2009
    #1
    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
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. iPhoneSpain thread starter macrumors newbie

    Joined:
    Sep 27, 2009
    #3
    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... :(
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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
     
  5. iPhoneSpain thread starter macrumors newbie

    Joined:
    Sep 27, 2009
    #5
    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!
     

Share This Page