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;
}
Related
For this problem, I created a new project with a single view.
I set a url scheme and added a label in the view.
And code is here.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
ViewController *vc = (ViewController *)self.window.rootViewController;
vc.textLabel.text = [NSString stringWithFormat:#"%#\n%#",vc.textLabel.text,url.absoluteString];
return YES;
}
It works fine.
But if I add some time-consuming operations at app initialize,
like this.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[NSThread sleepForTimeInterval:1];
return YES;
}
Then I found this problem through those steps:
use safari to start the app through input the url scheme
wait it jumps to the app, and press the home button immediately
tap the app icon to continue
get two lines of url on the label
UIApplication calls application:openUrl: multiple times.
I tried using this delegate, same problem.
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
You can press the home button and tap the app icon multiple times, than openUrl will be called multiple times, it depends on cost of time-consuming operations.
I tested on iOS 9.3.3 and iOS 9.3.1, got same problem.
I tried on iOS 8.1.2 and iOS 10.2 not found this problem.
Any ideas/suggestions would be highly helpful & very thankful
I followed the instructions on http://www.appcoda.com/ios-programming-facebook-login-sdk/
It works, but magically
I don't understand this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FBLoginView class];
[FBProfilePictureView class];
return YES;
}
What does sending the class message to these classes do? I don't find it in the facebook ios documentation
Calling anything on an NSObject has the side effect to call the lazy initialize method once.
That's how FBLoginView is doing its magic. It would have work with [FBLoginView self]; too.
Using a PFLogInViewController subclass in my app to allow users to login with Facebook, I have an issue.
While it works perfectly in some cases; in other cases it doesn’t.
After I give permissions to the user the “Loading…” spinning wheel comes up and stays there for ever.
And some times it works but the waiting time (with the spinning wheel) is a bit long.
Though I now have quite a bit of experience with Parse.com, this is the first time I try to integrate Facebook login, therefore I may well be doing something the wrong way.
Here is some of the code I use related to this:
In the AppDelegate.m I do:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
……
[PFFacebookUtils initializeFacebook];
……
return YES;
}
and:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL fbAppCallStatus = [FBAppCall handleOpenURL: url
sourceApplication: sourceApplication
withSession: [PFFacebookUtils session]];
return fbAppCallStatus;
}
In the CustomLogInViewController.m I do:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([PFUser currentUser]) [self quitView];
}
Let me know if there seem to be an obvious mistake here.
Thanks for any tip.
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
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