Firebase Auth iOS user Anonymously create but not showing in console - ios

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!!

Related

How do you log out of Firebase? (Objective-C)

I'm trying to log out users from my app. In the Firebase API, it says to use [ref unauth];
What exactly is the ref that I'm supposed to unauthorize? Is it a Firebase reference or the user's uid? I've used a Firebase reference, and it doesn't seem to do anything. How do I use this command? What exactly is it supposed to do? I haven't come across a good example.
NSError *signOutError;
BOOL status = [[FIRAuth auth] signOut:&signOutError];
if (!status) {
NSLog(#"Error signing out: %#", signOutError);
return;
}else{
NSLog(#"Successfully Signout");
}
Implement this code you must enjoy that it works for sign out.
The Firebase client manages the connection to its servers behind the scenes and authenticates on that connection instead of per Firebase object. This means that whenever you call for example ref authUser:#"jenny#example.com" password:#"correcthorsebatterystaple" on any Firebase reference, the user is authenticated on all references.
Similarly: when you call unauth on any Firebase reference, the user will be signed out of all references in your app.

Parse Log in With Twitter Initial Failure

Currently I have a Twitter login that authenticates the user just fine, receiving all the appropriate information for the user necessary for confirming a complete login.
I then am calling the [PFTwitterUtils logInWithBlock:...] method in order to authenticate the user through Parse and populate a new user in _User.
(I am not using just this method to present the Twitter login dialog box as I could not get it to present itself).
Here is the strange part:
On the first time I launch the app, I sign in with Twitter, and then call the logInWithBlock method and receive the following error:
Something went wrong: The operation couldn’t be completed. (NSURLErrorDomain error -1012.)
The strange part is that this issue does not occur at all if I relaunch the app again. The only difference is that upon relaunch I believe the Twitter Account information that I had used before (via browser not accounts) is saved on the device. When I launch the app again, I have it set so that it reloads the previous session: this time the [PFTwitterUtils logInWithBlock:...] works like a charm, creates a new user, etc., without any issue.
NOTE: I have a valid URL saved as the Callback URL on my Twitter App's settings. Also, I hope it is clear that the setup was done correctly given that it works fine on second log in.
Here is the login code I am using:
// Login with Twitter through Parse
[PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) {
if (error != nil) {
// Something went wrong
NSLog(#"Something went wrong: %#", [error localizedDescription]);
breakLogin = YES;
[self invalidateSignInTimer];
return;
}
else if (user.isNew){
userObjectID = user.objectId;
[user saveInBackground];
NSLog(#"New User");
}
else if (!user.isNew) {
userObjectID = user.objectId;
[user saveInBackground];
NSLog(#"Returning User. Welcome Back!");
}
}];
I am running out of patience and ideas on why this is happening. If anyone has any ideas please let me know - thanks!
UPDATE:
I noticed that the reason this seems to be happening is such:
The first time i attempt to login there is no PFUser, whereas the second time there seems to be a saved [PFUser currentUser], which allows the [PFTwitterUtils...] method to log in and create the new user.
Yet I am still not sure how to prevent the failure the first time without manually creating a new PFUser and then logging in with Twitter, then PFTwitterUtils...
UPDATE 2
I have resolved this issue with the answer I have provided below. I am leaving this up as I feel this is something that may help others out there in the future.
So after extraneous research, I seemed to have found a solution.
First I made sure that all of my framework files (SKDs, headers, etc) were up to date by removing all of their references from both the project and the library linking.
Second I made sure that all keys and secrets were remade and updated in my
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Lastly I made double checked that I properly went through the set up for Twitter authentication through Parse's website.
BUT what I found to be the only solution rested in the Callback URL.
When specifying the Callback URL in your Twitter Application under "Settings", I had to uncheck the Lock Callback URL option, despite the recommendation by Twitter. (seen below)
I was a little unhappy that all of this trouble derived from something so mundane, however I was at least pleased that solution was in fact resolved without too much trouble. Hopefully this answer helps someone out there struggling with a similar issue.

Forced to create a new Quickblox session every time iOS app is opened

I am using the Quickblox iOS SDK 2.0.12
I have been following the instructions on Quickblox Authentication and Authorization here.
I call QBRequest createSessionWithSuccessBlock:, and then call QBRequest signUp: inside it's completion block, and then I call QBRequest logInWithUserLogin: inside the next completion block.
According to the above link, I should now have a Quickblox User Session after doing all of this. This all works perfectly and all of the calls are successful and I can see that the user is now in the Quickblox Admin Panel.
After doing this, if I make Quickblox requests they work fine. The only weird thing is that [[QBSession currentSession] currentUser] NSLogs as (null).
Anyways, if I stop running the app on the simulator, and then run the app again 10 minutes later, I check for persisted custom data so I can see if the user has already signed up or not. When the user has signed up, then I take them into the app instead of them needing to signup or login again.
Now, if I try to make any requests to Quickblox, I get the following exception:
Terminating app due to uncaught exception 'BaseServiceException', reason: 'You have missed the authorization call.
Please insert following code inside your application
[QBRequest createSessionWithSuccessBlock:errorBlock:];
Before any other code, that uses our service, but after setup credentials. Thank you.'
I don't understand why it's saying I need to create a session when I already just created one when the user first signed up. I understand that the session expires every 2 hours, but I am testing this very quickly and I am always receiving this error.
If I NSLog [QBSession currentSession] I can see that there is currently a QBSession object, but if I try to NSLog any of it's properties like sessionDetails, sessionExpirationDate, or currentUser they all log as (null).
As I know, only if you use this method - (void)startSessionForUser:(QBUUser *)user withDetails:(QBASession *)session expirationDate:(NSDate *)sessionDate , you can use this property correct. But I didn't ever use it.
For recreating a session I use [QBConnection setAutoCreateSessionEnabled:YES] and for chat I keep QBUUser in my Manager, and after entering foreground I check XMPP connection [[QBChat instance] isLoggedIn]. Maybee it may help you.

Save game data into iCloud via GameKit

I'm trying to save game's data to iCloud via next code:
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer saveGameData:[NSData dataWithBytes:rawData->data() length:rawData->size()]
withName:[NSString stringWithUTF8String:fileName.c_str()]
completionHandler:^(GKSavedGame *savedGame, NSError *error) {
if (error == nil) {
DebugLog(#"Snapshot successfully saved");
} else {
DebugLog(#"saveSnapshot error: %#", error.description);
}
}];
But getting error message: The requested operation could not be completed because you are not signed in to iCloud
I've tried to do this in iOS Simulator and on device but didn't succeed.
And tried to use test apple ID, dev apple ID, new apple ID, but didn't succeed too.
User is logged in to iCloud in iOS Settings and logged in to Game Center.
Any suggestions?
I had a similar issue. After I signed in with my iCloud account on my device's settings, the exact same error was still showing up, and it only stopped when I enabled the iCloud Drive for my account, otherwise it will never work.
So, it looks like the user must be using iCloud Drive, otherwise GKSavedGame will never work. Apple docs never mention that as far as I'm aware.
Prerequisite:
You must have an Apple ID.
Check you have your Capabilities set.
Capabilities > iCloud > ON
(You must have iCloud Documents checked.)
Capabilities > Game Center > ON
Go to iCloud and create your account
From your computer browser, just login with your Apple ID and accept the terms and conditions. Like here: https://www.icloud.com/#settings
Now you can log in with your device or simulator, in Settings > iCloud.

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.

Resources