Reenabling GameCenter after user-cancelled ios9 - ios

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.

Related

Stop Do you want to open facebook prompt when i called "logInWithReadPermissions" method in iOS

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.

How to use system build-in passcode screen to authenticate my App when user clicks Enter Password

I'm integrating TouchID into my app, How can I use 'Enter passcode' option present system build-in passcode screen to authenticate my app.?
Any one please explain how to handle case 'LAErrorUserFallback' in objective C.
You cannot do that. What you can do is use that option to show your own password screen. In your reply block you check the NSError object and switch off the fallback code.
....replyBlock:^(BOOL success, NSError *error) {
if (error)
{
switch (error.code)
case LAErrorUserFallback:
Now here you can do whatever your app wants to do for app specific, not device specific, authentication. (Basically, you can do whatever you did before you had Touch ID available.)
Update:
See NicolasMiari's comment, which refers to https://www.secsign.com/fingerprint-validation-as-an-alternative-to-passcodes/ which may have a solution.

How to detect if someone has removed the app from facebook and is revisiting the 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.

How to detect when user delete the app from Facebook

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.

Is there any way to control when authentication with Game Center happens?

The following code is called once upon applicationDidFinishLaunching:; however, it runs each time my app re-enters the foreground again.
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated)
{
// Some implementation
}
}];
This makes sense, according to the Game Kit Programming Guide:
... it also retains your completion handler for later use. Each time your application is moved from the background to the foreground, Game Kit automatically authenticates the local player again on your behalf and calls your completion handler to provide updated information about the state of the authenticated player.
Is there any way to delay this authentication until Game Center is actually needed? The reason I ask is that I would like to avoid showing the "Welcome back, userX!" banner each and every time the app is brought to the foreground.
No, you can't, at least not with public APIs.

Resources