Time-appended app: openURL doesn't fire

For some reason I am developing a static library for facebook connection.

For a correct authorization process, the URL appDelegate must have - (BOOL) app: (UIApplication * app) openURL: (NSURL *) url sourceApplication: (NSString *) sourceApplication annotation: (ID) annotation

method. So when I code it in the appDelegate.mm file everything works well, the method call and facebook session become authorized. But I have to add this method for runtime delegation, so I use the following code:

{
NSString* methodDescription;

methodDescription = @"B@:@@@@";
UIApplication* app = [UIApplication sharedApplication];

bool res = class_addMethod([app.delegate class],     @selector(application:openURL:sourceApplication:annotation:), (IMP)applicationIMP,     [methodDescription UTF8String]);
NSLog(@"Result of add method is %d", res);
}

      

// a new method is implemented here:

 bool applicationIMP(id self, SEL _cmd, UIApplication *application, NSURL *url, NSString     *sourceApplication, id annotation)
 {
NSLog(@"Log from applicationIMP injected method");
return [[LibSocial sharedInstance] FacebookHandleOpenURL:url];
 } 

      

this code adds method successfully (I see this method when calling class_copyMethodList): 2013-02-04 23: 02: 00.704 LibSocialTest [38167: 19a03] Mathod [0] - application: openURL: sourceApplication: annotation:

But Facebook SDK does not run this method after authentication and I got FBSessionState FBSessionStateClosedLoginFailed.

Why hasn't this method been run?

Update: Even if I replace the normally implemented method with a custom implementation at runtime, everything works fine and a new implementation of the method is triggered in the Facebook SDK. But if I didn't normally code this method, but add it at runtime, it doesn't work.

Update2 If I add a method to the appDelegate class before instantiating the UIApplication (in the main.m file) then the input method works (even if there is no default implementation in the appDelegate.mm file), but if I inject the method after creating the UIApplication (so the class instance appDelegate too), then method injection does not affect already created class instances.

+3


source to share