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
Related
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;
}
He guys, I am doing a photo share in my cocos2d application with Facebook SDK. I've a problem that: the login view with status Not Logged In is remaining even after authentication. I'm attaching the images:
Problem: After clicking the Skip or OK button of the Authentication page, the status has to be changed as Login. But it isn't. No Facebook delegates are getting called after Auth(When I enter the page first time, loginViewShowingLoggedOutUser delegate was get called. After auth, nothing is get called.).
What I've done already:
Downloaded the Facebook SDK, attached to the project.
Added FacebookAppID,FacebookDisplayName and URL Schemes in info.plist.
Tried the integration with my cocos2d app.
Added <FBLoginViewDelegate> in .h.
Added loginview.delegate = self in .m.
I'm also uploading the screenshot of what I've done in my info.plist:
I am creating the login view as:
// Create Login View so that the app will be granted "status_update" permission.
FBLoginView *loginview = [[FBLoginView alloc] init];
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
#ifdef __IPHONE_7_0
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
if ([self respondsToSelector:#selector(setEdgesForExtendedLayout:)]) {
loginview.frame = CGRectOffset(loginview.frame, 5, 25);
}
#endif
#endif
#endif
loginview.delegate = self;
[[[CCDirector sharedDirector]view]addSubview:loginview];
[loginview sizeToFit];
What I found:
The following method in appdelegate is not get called:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
fallbackHandler:^(FBAppCall *call) {
NSLog(#"In fallback handler");
}];
}
Further info:
Xcode Version 5.0.1
iOS Version 7.0
facebook-ios-sdk-3.9
Any help ASAP is appreciable.
Thanks.
Sorry guys.... #elio.d: and thank you very much for your valuable suggestion . That was my mistake with coding. I have pasted the following method, just above #implementation AppController. What an idiot I am. This just wasted one of my whole day... :
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
}
This just saved me. Hope this might be helpful for some others like me. :)
You have to add an url scheme in your app to make the facebook app / website call your app back after login or authorization link to the documentation, this is the reason why your app is not called
I'm using Facebook SDK 3.8 in my app.
I am using the FBLoginView graphically to login Facebook user.
I have a few views in my app:
ViewController (the main view when the app is launched)
LoginViewController (the view with the FBLoginView)
StoryViewController (the view that only allows authenticated Facebook user to access)
On ViewController, user click on View Story button and I use segue to direct user to LoginViewController if he is not yet sign in with Facebook.
On LoginViewController, user clicks on the Log in with Facebook, then the app prompts user for some permissions I set, and after user clicks Ok, it just returns back to the LoginViewController.
My question is:
How to transition over to the StoryViewController once user has accepted the permission and logged in to Facebook, in Storyboard mode?
I have the method (below) inside my LoginViewController.m but it is never called.
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView
What I'm doing wrong?
EDIT:
I have this inside my AppDelegate.m
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
//return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}
and I have this inside my ViewController.m
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
NSLog(#"To get FB user profile...");
}
But from the debugger, I didn't get the message "To get FB user profile..."
//Are you implementing this method in AppDelegate ? If not implement it.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// FBSample logic
// We need to handle URLs by passing them to FBSession in order for SSO authentication
// to work.
return [FBSession.activeSession handleOpenURL:url];
}
//And u can push your view controller i.e. StoryViewController in this delegate method of fbloginview
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
//you can navigate to your view controller
}
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
I'm trying to implement SSO following the Tutorial:
https://developers.facebook.com/docs/mobile/ios/build/
At the end of Step 3, I'm supposed to Test my App running it on Simulator. The Run succeeded but all I see is a Blank View (screen). I'm not sure if I need to create the view called "authorization dialog" including the FB logo, buttons, etc or if it's automatically created by code I've implemented using Facebook SDK.
Also, I'm using a storyboard and wonder if that's the problem.
I think that it's because you have once signed in and now you haven't logged out so it is already authorized and hence you cannot see anything :)
Is your initial ViewController blankView ? Because the SSO only validates/autorize the session, you need to implement the UI in your ViewController.
If you implement it in Storyboard I suggest you to do most of the code in your controller file, since I was stucked there for quite long time. But make sure to put this code in the app delegate file.
#pragma mark Facebook
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [self.facebook handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication: (NSString *)sourceApplication annotation:(id)annotation {
return [self.facebook handleOpenURL:url];
}
Also in the delegate file you should instantiate the Facebook object before you use the in the above methods.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
viewController *controller = [[viewController alloc] init];
// Initialize Facebook
facebook = [[Facebook alloc] initWithAppId:#"Your app ID in string" andDelegate:controller];
// Override point for customization after application launch.
return YES;
}