Search code examples
iphoneiosudid

override uniqueIdentifier method of ios


I need to send a different udid to my database for few testing purpose. Since [UIDevice currentDevice] uniqueIdentifier] is called in almost 15 places it will be very difficult for me to make a code change and then test. Is there a way to override that method for a while and send a another number as udid ?


Solution

  • You should be able to override it in a category on UIDevice. Create a header like this:

    @interface UIDevice (overrideId)
    
    @property (nonatomic,readonly,retain) NSString *uniqueIdentifier
    
    @end
    

    And then a .m like this:

    @implementation UIDevice (overrideId)
    
    - (NSString *)uniqueIdentifier {
        return @"whatever";
    }
    
    @end
    

    Don't forget to remove it again before releasing.