I'm new to using the Facebook SDK and I wondered how detect when the user deletes the app from his Facebook account. Currently if we delete the app, and we want to post something from my app, I'm getting an error message.
Try this:
[FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) {
if (!error) {
if (result == ACAccountCredentialRenewResultRejected) {
NSLog(#"Facebook app deleted");
}
}
else {
NSLog(#"Error: %#", error);
}
}];
http://developers.facebook.com/docs/authentication/#app-deauthorization
https://developers.facebook.com/apps/
go to your app's edit screen
click on advanced in the left side column
'Deauthorize Callback' setting should be near the top
App Deauthorization
When a user of your app removes it in the App Dashboard or blocks the
app in the News Feed, your app can be notified by specifying a
Deauthorize Callback URL in the Developer App. During app removal we
will send an HTTP POST request containing a single parameter,
signed_request, which contains the user id (UID) of the user that just
removed your app. You will not receive an user access token in this
request and all existing user access tokens will be automatically
expired.
Related
Suddenly this behaviour started to happen without changing anything. Basically, I'm able to create users Anonymously or even with Email/Password. I get no error whatsoever, actually I'm able to retrieve the userID. However, when I go to the users list in the console, its always empty.
Auth.auth().signInAnonymously() { user, error in
self.ifNoError(error) {
print("Signed In Anonymously \(user?.user.uid)")
}
}
Results:
Signed In Anonymously Optional("qQazZ3MX8LfQdnlz8F27QDxAT9U2")
Thank you in advance
Did you at any point delete anonymous users from the Firebase console before going live or something like that? That's what I did, not realizing that firebase keeps that user alive on your device...even if you delete the app from the device and re-install. Moreover, it will still work as an accepted anonymous user (even though deleted from the console) UNTIL you force a sign out on a given device. (Oops. TL;DR). Try this.
Sign out the user in your app delegate
FIRAuth *auth = [FIRAuth auth];
NSError *error;
[auth signOut:&error];
Create another anonymous user
[auth signInAnonymouslyWithCompletion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) {
NSLog(#"Error is %#", error);
NSLog(#"Auth result user id is %#", authResult.user.uid);
}];
In my case, my device now showed a new user UUID and that user shows up in the Firebase console.
Fun fact: This issue doesn't seem arise with Android. My Android app, which shares the same production firestore, happily created a new user after I deleted the app from the device and reinstalled.
I managed to solve the issue by creating a manual user email/password (manually on the console), sign in with it through code, delete it thorough code. Then change the code to sign in again Anonymously. This solved the problem!!
I am using iOS SDK Facebook to login into my app. I have a Facebook login button (my own button, not the one provided) and it shows perfectly either the Facebook App (if is installed) or the Safari, and after that the facebook login page.
ISSUE: When i installed facebook and i click login with facebook button its asking "Do you want to open facebook" with open and cancel button. when i click open button the handler calling automatically.
[login logInWithReadPermissions:#[#"public_profile",#"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
//Checking for success login
if (result) {
//user login successfully, get user information
} else {
//user login failed
NSLog(#"facebook error %#", error);
}
}];
When i tried to get user inoformation in success method iam getting error.How can i stop asking prompt Do you want to open facebook when i click on facebook button first time. And why success block is calling when i press open button.
Change the login behavior to:
login.loginBehavior=FBSDKLoginBehaviorWeb;
As default login behavior is via the application or native safari browser.
Changing it will prevent prompt from opening.
I am trying to sign in game center usign following code :-
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
{
if (error == nil)
{
NSLog(#"Authentication Successful");
}
else
{
NSLog(#"Authentication Failed");
}
}];
:- At first it opens the gamecenter but when user press cancel button and comes again the game center screen is not opening and showing the following error "The requested operation has been canceled or disabled by the user".
Please suggest when this happening and how correct it.
Regardless of whether you're using the deprecated method in the original post or the current preferred mechanism (as of this writing),
[[GKLocalPlayer localPlayer] setAuthenticateHandler:^(UIViewController *loginViewController, NSError *error)
{
}];
you only get one shot at authenticating. If you try setting the authentication handler again later, the login screen will not appear again. These links talk more about that:
Game Center login dialog not shown again after cancelling it for the first time (iOS7)
ios: programmatically ask for Game Center sign-in?
Killing the app (not just switch away, but actually close the app) and restarting it will cause the login to appear again when you attempt to authenticate. Alternatively, switching to the game center app should allow the user to log in.
So, in my app, I check the error code. If the user cancels, the error.code in the handler will be set to 2. When I see this value, I disable all game center functionality and I put up a notice to the user stating what they need to do to complete logging in.
I just started using facebook sdk and slightly confused with it documentation. It's well written, but very often does not correspond to current SDK version. So i'm not found what to do with this situation:
I request publish permissions when firstly require them, with the next code:
[[FBSession activeSession] requestNewPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (error) {
NSLog(#"Permissions request error: %#", error.description);
}
completion(error == nil);
}];
I need only one publish permission - 'publish_actions', when i request it sdk redirects me to facebook app and immediately returns back to the my app without asking whether i'm agree to give this permission.
There are no errors in completionHandler, but through debug i found that this permission was saved in the variable _requestedReauthPermissions:
So, finally, permission i requested not granted to me.
How properly request publish permission? What could I miss? May it occur due to setup of facebook app?
This is one of the test cases, that needs to be verified.
Someone removes your app from Facebook via app settings and revisits your app. Your app should detect this and prompt the person
to log back in. Go to your app and tap on the "Log in with Facebookâ
button Tap OK to accept the read permissions (and OK again to accept
write permissions where applicable) Go to app settings on Facebook and
remove your app Repeat steps 1-2 and verify that Facebook Login works
I have found no way to achieve this. When I remove the app in facebook, my iOS still believes the session is valid. Here on Stackoverflow seems there was a discussion this regarding. But the solution provided doesn't seem to work.
This is what I have so far to login. But I can't detect when the user has removed the app on facebook. Any advice please?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
NSLog(#"Found a cached session");
// If there's one, just open the session silently, without showing the user the login UI
[FBSession openActiveSessionWithReadPermissions:#[#"public_profile"]
allowLoginUI:NO
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
// Handler for session state changes
// This method will be called EACH time the session state changes,
// also for intermediate states and NOT just when the session open
[self sessionStateChanged:session state:state error:error];
}];
// If there's no cached session, we will show a login button
} else {
UIButton *loginButton = [self.customLoginViewController loginButton];
[loginButton setTitle:#"Log in with Facebook" forState:UIControlStateNormal];
}
}
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
// If the session was opened successfully
if (!error && state == FBSessionStateOpen){
NSLog(#"Session opened");
// Show the user the logged-in UI
[self userLoggedIn];
return;
}
if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
// If the session is closed
NSLog(#"Session closed");
// Show the user the logged-out UI
[self userLoggedOut];
}
}
If a user goes to Facebook settings and removed the app, Facebook posts to the "deauthorize callback url" that you set up in the app settings. This will include the same signed request as a canvas app, so you can get the id from there and do whatever you need to do to keep track of that user having removed your app.
As #Tom Kincaid said, you can use the Deauthorize Callback mechanism to receive a call from FB to one of your backend endpoint. See the docs at https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.1#deauth-callback
You could store the user_ids in a separate table, or having a flag for the removal in your existing user table or object structure.
Then, your app can check upon loading whether the user is still "active", or is marked as having the app removed, and act accordingly.