For some reason I develop static library for facebook connection.
For proper process authorizated URL appDelegate should have
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
method.
So when I code it in appDelegate.mm file all works well, method invokes and facebook session become authorized.
But I have to add this method to delegate in runtime, so I use follow 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);
}
//here is implementation of new method:
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 successfully adds method (I see this method when calls class_copyMethodList):
2013-02-04 23:02:00.704 LibSocialTest[38167:19a03] Mathod[0] is application:openURL:sourceApplication:annotation:
But Facebook SDK doesn't fire this method after authentication, and I got FBSessionState FBSessionStateClosedLoginFailed.
Why this method didn't fired?
Update:
Even if I replace normally implemented method with custom implementation at runtime, all works well and Facebook SDK fires new method implementation. But if I didn't code normally this method, but add it at runtime, it isn't fires.
Update2
If I add method to appDelegate class before instantiating UIApplication (in main.m file), then injected method works (even there are no default implementation of method in appDelegate.mm file), but if I inject method after UIApplication was created (so instance of appDelegate class was created too), then injection of method doesn't affect on already instantiated instances of class.
Related
So, it is pretty clear question I think. This question is about monitoring ajax requests. I tried it but didn't work as I wanted.
How can I call a function in my native iOS Obj-C application every time a request is sent, received and the browsing link is changed in WKWebView?
Ok, I found a way.
You can create a new class (let's call it MyURLProtocol) which has NSURLProtocol as subclass. Then add this function to MyURLProtocol:
+ (BOOL)canInitWithRequest:(NSURLRequest *)request {
NSLog(#"URL = %#", request.URL.absoluteString);
return NO;
}
This function will be called each time your webview makes a request. And then you need to register this protocol with the loading system. In your Appdelegate.m file include your class and add/replace didFinishLaunchingWithOptions function with this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[NSURLProtocol registerClass:[MyURLProtocol class]];
return YES;
}
All set. Now you can edit canInitWithRequest function and do what you want with the request.
I need to Swizzle UIApplication class methods especially "application:handleOpenURL:". I have added a category class of UIApplication. I have exchanged my own method with the original method but, it never triggered. The Swizzle class called very first time of app launch but, the swizzle method never triggered. I have attached the code for your reference.
- (BOOL) xxx_application: (UIApplication *) application handleOpenURL: (NSURL *) url {
NSLog(#"\n\n Swizzle handle open url..");
[self xxx_application:application handleOpenURL:url];
NSLog(#"URL: %#", url);
return YES; }
Can anyone please save my day? I tried of using some private library like "RSSwizzle" but, no help.
You don't need to swizzle this method, and it doesn't exist on UIApplication anyway. It is a method that is part of UIApplication's delegate protocol, meaning that (typically) your "app delegate" class should simply implement the method to have it called.
I am using the FBLoginView (version 3.xx) in my app to automatically create useraccounts based on their Facebook profile, but the delegate callbacks of FBLoginViewDelegate don't get called anymore.
My code is as folloows:
In the didFinishLaunchingWithOptions method of my AppDelegate I have this line:
[FBLoginView class];
I have a class called LoginHandler that conformes to the FBLoginViewDelegate protocol and which implements these methods:
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error
In the viewDidLoad method of my view controller I have this code:
self.fbLoginView.readPermissions = #[#"public_profile", #"email"];
self.fbLoginView.delegate = [LoginHandler sharedInstance];
I also have set up my Info.plist with:
FacebookAppID (containing <my-app-id>)
FacebookDisplayName (containing my app name=
CFBundleURLSchemes (containing fb<my-app-id>)
When I press the Facebook login button it switches over to the Facebook app, asks about the permisions (only the first time) and returns to my app. However, none of the delegate methods get called at this point. This used to work before and I did get callbacks for both loginViewShowingLoggedInUser and loginViewFetchedUserInfo, but some time ago it stopped working and I simply can't figure out what changes have broken it.
An interesting thing is that every time I start the app (before I do anything with the Facebook button) my loginViewShowingLoggedOutUser gets called. I don't know if it is related to my issue or if this is normal behaviour.
I have found the answer. I needed to override this method in my app delegate.
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
// You can add your app-specific url handling code here if needed
return wasHandled;
}
I'm using the application:openURL:sourceApplication:annotation: to open a file with an extension .ftl. This is declared in my app's info property list.
The .ftl file is attached to an email, and when touched calls an ALREADY LAUNCHED app. The code works fine in IOS 4, but in IOS 6 the above app delegate method isn't called.
The code is in my app delegate is simply:
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(#"method is called");
if (url != nil && [url isFileURL]) {
[self performSelector:#selector(splashFade) withObject:nil];
NSLog(#"inside if statement called");
//Calls singleton to delete existing data, parse and ingest supplied new file data into Coredata:
[[ContentController sharedInstance] deleteSectorList:(NSURL *)url];
}
return YES;
}
Does anyone have any idea why this method is no longer called?
Thanks.
You have to tell the phone that your app accepts certain files. You do this by going to the info.pList and there you add a flag.
Follow this link which will cover this subject. https://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html%23//apple_ref/doc/uid/TP40010411-SW1
In the documentation from facebook to integrate their sdk in iOS app, they mentioned everything in app delegate. But in my application, i've settings view which has option for "Facebook". When user clicks that then only i want to enable single sign on from my application. This can be done by creating facebook object etc in my settings view controller. But in app delegate, they are asking to ad the following code:
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [facebook handleOpenURL:url];
}
And both the above methods has to be implemented in app delegate class with "facebook" as object. But I'm creating my facebook object in my settings view controller. How should I handle this situation?
Add this to your AppDelegate.m (and add it to the .h header file)
+ (AppDelegate*) sharedAppDelegate {
return (AppDelegate*) [UIApplication sharedApplication].delegate;
}
Include the header file and do this to access your facebook object from any view controller:
[[AppDelegate sharedAppDelegate] facebook]
as mentioned in the docs, I'm creating the facebook object and calling the methods in app delegate from the settings view