In which situation are those Facebook IOS FBSessionDelegate methods called? - ios

It's clear to me that these are called upon login if a user grants or denials permission:
- (void)fbDidLogin;
- (void)fbDidNotLogin:(BOOL)cancelled;
But i was wondering when the following FBSessionDelegate methods could be called:
- (void)fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt;
- (void)fbDidLogout;
- (void)fbSessionInvalidated;
The documentation says:
//Called after the access token was extended.
- (void)fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt;
//Called when the user logged out.
- (void)fbDidLogout;
//Called when the current session has expired.
- (void)fbSessionInvalidated;
Now when would such a thing happen? When i call the following?
[Facebook authorize:nil];
There is no chance i will get a fbDidLogout call back right?
Maybe if a user removes my app from his Facebook account via the Facebook app, would this method be called than? No, because my app doesn't open in that case..
...so in which situation would these be called?

I think i found it myself...
This one:
- (void)fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt;
Could be called when you call:
[facebook extendAccessTokenIfNeeded];
This one:
- (void) fbDidLogout;
Gets called when you call
[facebook logout] //(of course..)
The last one:
- (void)fbSessionInvalidated;
Get's called when you try to send a http request to Facebook with an expired session token.
I found it in the Facebook SDK header file Facebook.m
I'll leave the question here for anyone looking for the answer :)

Related

Google SignIn complete vs manual app switch

When using [GIDSignIn sharedInstance].allowsSignInWithWebView = NO how can I tell the difference between the user completing the Google SignIn process or manually switching back to my app?
If user completed google sign in (successfully or not) GIDSignInDelegate method - (void)signIn:didSignInForUser:withError: will be called. If its not called, then probably user just returned manually... Also, you can check in your app delegate: google sign in will return to your app by using the url scheme, as a result this methos will be called: application:openUrl:sourceApplication:annotation

Google+ integration iOS - EXC_BAD_ACCESS error on signout

I've done google+ integration in my app and it works perfectly fine. But I have noticed that occasionally I receive an EXC_BAD_ACCESS error during logout. This is my logout function
-(void) logout
{
[[GPPSignIn sharedInstance]signOut];
[[GPPSignIn sharedInstance] disconnect]; // EXC_BAD_ACCESS Error occurs in this line
}
I dont always get this error, I think it may have to do something related with session. I've tried searching for it but haven't found any resolution so far. This error occurs very rarely and I dont know when exactly this happens. When I run the app after this error it works fine and there are no issues. But still its an error and I was wondering if anyone else had the same experience and had found any workaround for this.
The problem seems to be due to calling both signOut and disconnect methods. The disconnect method also performs the signout. The docs say "The token is needed to disconnect so do not call signOut if disconnect is to be called."
If you want to only sign out the user, just call the "signOut" method, for example:
- (void)signOut
{
[[GPPSignIn sharedInstance] signOut];
}
If you want to disconnect the user (revoke your app's API access on behalf of the user), the method also performs sign out:
- (void)disconnect
{
[[GPPSignIn sharedInstance] disconnect];
}
You should also implement the didDisconnectWithError:(NSError *)error method for cleaning up the user details and following Google+'s policies around disconnects.
Read the official Google+ iOS docs for more information.

Facebook app invite delegation mixup

I'm sending a Facebook app-invite from my iOS app, and am trying to implement a success/fail flow using blocks.
I have created a class to wrap my communication with the Facebook SDK which exposes a send invite method.
In that method, I have the following code:
[self.facebook dialog:#"apprequests"
andParams:params
andDelegate:self];
as explained in the documentation.
My wrapper class conforms to the FBDialogDelegate protocol, and I have implemented 5 of the delegate methods:
dialog:(FBDialog *)dialog didFailWithError:(NSError *)error,
dialogCompleteWithUrl:(NSURL *)url,
dialogDidComplete:(FBDialog *)dialog,
dialogDidNotCompleteWithUrl:(NSURL *)url
dialogDidNotComplete:(FBDialog *)dialog
The problem is that wether the user cancels the dialog or sends the request, the only method that is being called is the dialogCompleteWithUrl:(NSURL *)url method.
Can anyone explain this?
This seems to be an outstanding issue that has been reported several times. The fact that didComplete is called when the user presses the cancel button is indeed a valid action so it is by design that didComplete gets called. The documentation might be outdated and we have a task to fix it, but reporting a doc bug on our developer site will allow you to track the progress.
So to answer your question, if the user presses the 'x' button it should call didNotComplete. User pressing send or cancel will call didComplete as it is designed that way.
However, this person came up with a good workaround for FBDialog where you can probably do something similar, such as checking the value of the URL when it succeeded vs when the user presses cancel and have an if check that checks for that case.
Hope this helps.

fbDidLogin did not called at first time in iOS. So I modified, is this the right process?

My fbDidLogin delegate method didn't called at first time. I searched and found "fbDidLogin not called" and "IOS - Facebook SDK fbDidLogin not called — initialize view controllers" and handled the facebook url into my Application Delegate correctly. But fbDidLogin method didn't called. So I searched again. Someone says in "Problems with fbDidLogin never called iOS" to change
[self authorizeWithFBAppAuth:YES safariAuth:YES];
into
[self authorizeWithFBAppAuth:NO safariAuth:YES];
in my Facebook.m file. After doing that my facebook login view just changed, yet couldn't get what I need. In that situation what I did? I added a line
[facebook logout:self];
right after
[facebook authorize:permissions];
Because I thought there is a problem in login or/and logout syncronisation, so if I call facebook logout method it might (yes, MIGHT) work.Voila! it does work, at least for me.Now all I want to ask you, is there any problem or logical error in my process? And is there a better way to do so?

iOS app expected behavior after the user removes the previously added authorization from the Facebook app?

I'm successfully posting to Facebook from our Unity iOS game by initializing at game launch then posting message by first checking the session validity and triggering the login if needed.
At first call, I authorize the game from the Facebook app.
Trying to start the process again, I go to the Facebook app prefs and delete the app authorization.
Now when I try to post again from the game, the post message completion handler has no errors but the post does not appear on the user's wall.
What is the process to correct this? Is there a way to check that the game is authorized before posting, and ask for a new authorization if it's not?
Or is the user decision final and they need to reinstall the app to reset everything?
Even though I'm using Prime31's Facebook plugin for Unity, I'm interested in an iOS SDK answer to this question.
Thank you!
You will get an exception, that you need to handle.
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error{
NSLog(#"didFailWithError : %#",[error description]);
NSDictionary* userinfo=[error userInfo];
NSString *type=[[userinfo valueForKey:#"error"]valueForKey:#"type"];
if([type isEqualToString:#"OAuthException"]){
NSLog(#"Exception from oauth let's take new token");
[facebook authorize:_permissions delegate:self];
}
}
Use this delegate function to handle exception.

Resources