fbDidLogin not called - iOS - iphone

I'm trying to implement facebook to my iOS app for a school project however I ran into a bit of a snag, namely the fbDidLogin method is not called.
I have created a sample object called FBFetcher as so:
#interface FBFetcher : NSObject <FBDialogDelegate,FBSessionDelegate,FBRequestDelegate> {
Facebook *facebook;
FBFetcher *facebookFetcher;
}
-(void)login;
#property (retain) Facebook *facebook;
#property (retain) FBFetcher *facebookFetcher;
#end
In the FBFetcher.m:
#implementation FBFetcher
#synthesize facebookFetcher,facebook;
-(void)login{
facebook = [[Facebook alloc] initWithAppId:#"...."];
NSArray *permissions = [[NSArray arrayWithObjects: #"offline_access",#"user_about_me", nil] retain];
[facebook authorize:permissions delegate:self];
}
-(void)fbDidLogin {
NSLog(#"Erfolgreich eingeloggt....");
}
#end
In my app delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[[controller facebookFetcher] facebook] handleOpenURL:url];
}
I have a separate view controller with n action tied to a UIButton:
facebookFetcher = [[FBFetcher alloc] init];
[facebookFetcher login];
I can access the login and authorization page, however the method fbDidLogin never gets called. Any suggestions?

The method never gets called because when you authorize, you are doing it in Safari. To take care of this, which I think is a bug from Facebook SDK by the way, open the facebook.m file and find the following line:
[self authorizeWithFBAppAuth:YES safariAuth:YES];
and change it to
[self authorizeWithFBAppAuth:NO safariAuth:NO];
This way you will never be sent to Safari, but everything will be done in a dialog.
Just test it and you'll see that the fbDidLogin method will get called.
Hope it will help

What about
- (void)fbDidNotLogin:(BOOL)cancelled
Does that get called?

Look for this function in Facebook.m. This is where Facebook calls your fbDidLogin function. First make sure this is being called, then debug into it. Make sure you've spelled/defined fbDidLogin correctly in your session delegate (no parameters). If not the respondsToSelector will fail and never call your delegate's function.
- (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate
{
self.accessToken = token;
self.expirationDate = expirationDate;
if ([self.sessionDelegate respondsToSelector:#selector(fbDidLogin)])
{
[_sessionDelegate fbDidLogin];
}
}

Related

iPhone:- Wants to autoLogin through saved credentials in Facebook

In my app i have to login inside Facebook without using login page and directly move onto home screen of Facebook.
i have searched a lot but i didn't get anything.......
#interface Facebook (MyApp)
- (void)myAuthorize:(id<FBSessionDelegate>)delegate;
#end
#implementation Facebook (MyApp)
- (void)myAuthorize:(id<FBSessionDelegate>)delegate {
_permissions = [[NSArray arrayWithObjects:#"email", *(whatever you need)*, nil] retain];
_sessionDelegate = delegate;
[self authorizeWithFBAppAuth:NO safariAuth:NO]; // force in app auth
}
#end
Facebook *facebook = [[Facebook alloc] initWithAppId:MY_APP_FB_ID];
[facebook myAuthorize:self];
As far as I know, this is not possible. Because if you do this you will get the password for all the users and you can hack their account. So, FB does not allow this.

No interaction with Facebook iOS SDK dialog after switching to thread?

I'm playing around a little bit with the Facebook iOS SDK.
I have a TabBar App (with MainWindow.xib) and I successfully integrated the Facebook SDK.
The problem is that non of the Facebook pop up dialogs are responding to my user interactions.
For example. I want to post something in the wall. The Facebook SDK opens a dialog but if i try to interacte with the dialog it doesn't happen anything.
The log tells me: [Switching to process 2365 thread 0x12d07]
How can I fix it?
I'm using the simulator.
The important code int the AppDelegate looks like that, it's actually more or less the same like on developer.facebook.com:
Thank you a lot.
// AppDelegate.h
#interface AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate, FBDialogDelegate> {
Facebook *facebook;
}
#property (nonatomic, retain) Facebook *facebook;
#property (strong, nonatomic) IBOutlet UIWindow *window;
#property (strong, nonatomic) IBOutlet UITabBarController *tabBarController;
// AppDelegate.m
#implementation AppDelegate
#synthesize facebook;
#synthesize window = _window;
#synthesize tabBarController = _tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
facebook = [[Facebook alloc] initWithAppId:#"APP_ID" andDelegate:self];
if (![facebook isSessionValid]) {
[facebook authorize:nil];
}
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
#end
Kind regards.
You need a method that posts to a feed, like the one below
-(void)postToFeed
{
MyAppAppDelegate *sharedAppDelegate = (MyAppAppDelegate *)[[UIApplication sharedApplication] delegate];
[sharedAppDelegate.facebook dialog:#"feed" andParams:params andDelegate:self];
}
I just hit this same problem. The problem for me was that my UIApplication keyWindow had userInteractionEnabled = NO. So not having that extra UIWindow present fixed it for me (more below).
I found this code in FBDialog.m
- (void)showWebView {
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) {
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
_modalBackgroundView.frame = window.frame;
[_modalBackgroundView addSubview:self];
[window addSubview:_modalBackgroundView];
....
so it's going to add the dialog to the keyWindow. I only had one window, so I thought. It turns out SVProgressHUD will create a new window with user interaction disabled and make it the key window (makes sense).
I'm guessing other HUD style things do this to. I was only showing the HUD while some prep work was done, so by the time I can show the dialog, I can remove it anyway. So that was my fix.
I dug this up by calling
NSLog(#"%#", [[UIApplication sharedApplication] windows]);
NSLog(#"%#", [UIApplication sharedApplication].keyWindow);
right before I was about to show the dialog and noticed
I had two UIWindow's
the key one's userInteractionEnabled was set to NO
Hope that helps.

Facebook iOS - handleOpenURL & Tabbar Application

I'm having difficulties getting the Facebook Log In to kick back to the right view in my app and call the appropriate facebook functions.
In the example Facebook has simply [controller facebook] that is the view they start with. I am using a tabbar application though so I don't have the necessary reference. I made a pointer to the desired view and used it... it opened correctly but would not call any of the methods associated with facebook, specifically:
(void)fbDidLogin;
(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[*NotReferencedViewController* facebook] handleOpenURL:url];
}
Has anyone else run into this?
Not sure what example you're talking about, but you should create and store your Facebook object in a central place such as your Model or UIApplicationDelegate. Then it would be accessible through singletons so you always have access to it, for example:
[[UIApplication sharedApplication] delegate].facebook
So you can then access the facebook object from whatever view controllers need it.
When you do something like
NSArray* permissions = [[NSArray arrayWithObjects:#"email", #"read_stream", #"publish_stream", nil] retain];
[facebook authorize:permissions delegate:self];
specifying delegate:self means you will implement methods in that class that Facebook can call to inform you of certain events. One of those methods is fbDidLogin, and in there you can do whatever you need to:
-(void)authorizeFacebook {
NSArray* permissions = [NSArray arrayWithObjects:#"email", #"read_stream", #"publish_stream", nil];
[facebook authorize:permissions delegate:self];
}
// if the authorization succeeds it will come back to your app and call the method below
-(void)fbDidLogin {
// switch view, call the facebook graph, or do whatever else you like
}
You could do this in the app delegate itself, or in a view controller.
You can see the facebook delegate methods by inspecting the .h files of the facebook SDK: Facebook.h, FacebookRequest.h, etc.
Edit
And your handleOpenURL: method should look exactly as it does in fb's example (assuming you are not handling other url schemes):
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
http://developers.facebook.com/docs/guides/mobile/#ios

Delegate not being called

I've a viewcontroller "ResultsViewController" with a button called emailbutton. when this button is pressed, i want a function to be called from another view called "Illusions_AppViewController" (both these viewcontrollers are not linked).
Therefore i defined a protocol in the "ResultsViewController.h":
#protocol ResultsViewDelegate <NSObject>
#optional
- (void) resultspage;
#end
#interface ResultsViewController : UIViewController
{
id<ResultsViewDelegate> mydelegate;
UIButton *emailButton;
}
#property(nonatomic,retain) IBOutlet UIButton *emailButton;
#property (nonatomic,assign) id<ResultsViewDelegate> mydelegate;
#end
In the ResultsViewController.m :
-(IBAction)emailButtonPressed:(id)sender
{
NSLog(#"entered emailbuttonpressed");// the app enters this method and gets hanged
if ([mydelegate respondsToSelector:#selector(resultspage)]) {
NSLog(#"entered respondstoselector");// this is never displayed in the log-showing that the delegates doesnt respond to selector
[mydelegate resultspage];
}
}
In my other view, "Illusions_AppViewController.m":
- (void)resultspage{
NSLog(#"Entered results page");
ResultsPageController *resultspagecontroller = [[ResultsPageController alloc] initWithNibName:#"ResultsPageController" bundle:nil];
resultspagecontroller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:resultspagecontroller animated:YES];
}
Would appreciate if anyone can help me with this. I've no clue of why the delegate is not called. the app gets hanged as soon as i press the emailbutton. Thanks!
The implementation/use of delegates is wrong. Please refer to this tutorial.
Hope this helps.
Thanks,
Madhup
or is there any other way to get this done. i just need the results page function to be called whenever the email button is pressed. i tried using this way:
ResultsViewController.m
-(IBAction)emailButtonPressed:(id)sender
{
NSLog(#"entered emailbuttonpressed");
illusions_AppViewController *illusionsview = [[illusions_AppViewController alloc]init];
[illusionsview performSelector:#selector(resultspage)];
}
Now the results page function gets called, but the resultspagecontroller that it needs to display as a modalviewcontroller never appears.the app hangs, and no errors in the console either.
To answer your second question, you are on the right track. Simply create an instance of your Illusions_AppViewController and call the illusionsView method in it instead using:
- (IBAction)emailButtonPressed {
illusions_AppViewController *illusionsview = [[illusions_AppViewController alloc]init];
[illusionsview resultspage];
[illusionsview release];
}

How to get started coding In-App Purchase

I am working on in-app purchase. In my application we added the following code in appdelegate:
#import "InappPurchaseAppDelegate.h"
#import "MainController.h"
#import "MKStoreManager.h"
#import "MKStoreObserver.h"
#implementation InappPurchaseAppDelegate
#synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[MKStoreManager sharedManager];
navigationController = [[UINavigationController alloc] init];
[window addSubview:navigationController.view];
MainController *frontController =[[MainController alloc] init];
[navigationController pushViewController:frontController animated:NO ];
[frontController release]; // Override point for customization after application launch
[window makeKeyAndVisible];
}
and added the following code in our controller:
#import "MainController.h"
#import "MKStoreManager.h"
#import "MKStoreObserver.h"
#import "InappPurchaseAppDelegate.h"
#implementation MainController
-(IBAction)InappPurchase:(id)sender
{
[[MKStoreManager sharedManager] buyFeatureA];
}
I also added storekit framework but when the button is clicked nothing happens.
All you need to know is here: http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Overview%20of%20the%20Store%20Kit%20API/OverviewoftheStoreKitAPI.html#//apple_ref/doc/uid/TP40008267-CH100-SW1
It shouldn't take you more than half a day to implement it (maybe a bit more if the content resides on your servers and is not already in the bundle).
The simplest explaination is that your button is not properly configured to send the action message. To test either set a breakpoint for the method or log it like:
-(IBAction)InappPurchase:(id)sender
{
NSLog(#"Buyid method called");
[[MKStoreManager sharedManager] buyFeatureA];
}
If the NSLog or breakpoint are never hit, you need to check the button in Interface Builder and make such it's action is set to the InappPurchase method.
If the InappPurchase method is being called by the button then the problem is in the MKStoreManger object.