Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5 - Compiling Private APIs for debugging - specifically _enableRemoteInspector

I was looking for a method to debug JavaScript in UIWebView and came across some articles about _enableRemoteInspector specifically

http://atnan.com/blog/2011/11/17/enabling-remote-debugging-via-private-apis-in-mobile-safari/

I could not get the example code to compile though. I keep getting a "No known class method for selecctor" error. Not just a warning.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //Works
    [NSClassFromString(@"WebView") performSelector:@selector(_enableRemoteInspector)];

    //Won't compile
    //[NSClassFromString(@"WebView") _enableRemoteInspector];
}

So I tried performSelector and that works and the debugger works as described.

But how do you compile it without resorting to performSelector?

I am running Xcode 4.2.1 and my project uses the iOS5 SDK.

like image 835
Megasaur Avatar asked Dec 29 '11 10:12

Megasaur


1 Answers

This is due to the new Automatic Reference Counting (ARC) in iOS 5. The sample code you linked to makes an assumption that you're not using ARC.

If you weren't using ARC, [NSClassFromString(@"WebView") _enableRemoteInspector] would simply produce a "method not found" warning (because the method isn't declared publicly).

However, for various reasons when you've got ARC enabled this warning becomes an error. If you want it to compile without using performSelector you'll need to disable ARC.

like image 168
lxt Avatar answered Nov 14 '22 22:11

lxt