Reputation: 351
I use in my application Firebase Database and at the time of the first request for authorization or registration, I wait for a long time for the data.
The first request takes about 5-6 minutes and sometimes more. I suspect that my app caches all the information from the database and did the cancellation of this action by setting a flag in keepSynced NO
.
But even this did not help and I had to wait a very long time. All subsequent requests are quickly and data come instantly. Below is the code that I use on the first request.
self.ref = [[FIRDatabase database] reference];
[self.ref keepSynced:NO];
[self.ref observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
self.fireUser = [TSFireUser initWithSnapshot:snapshot];
[self configureController];
}];
code model:
TSFireUser *user = [[TSFireUser alloc] init];
NSString *token = [[NSUserDefaults standardUserDefaults] valueForKey:@"token"];
FIRUser *fireUser = [FIRAuth auth].currentUser;
if(token)
{
NSString *keyUserData = [NSString stringWithFormat:@"dataBase/users/%@/userData", fireUser.uid];
NSString *keyToParameters = [NSString stringWithFormat:@"dataBase/users/%@", fireUser.uid];
NSString *keyToPhotos = [NSString stringWithFormat:@"dataBase/users/%@", fireUser.uid];
FIRDataSnapshot *fireUser = [snapshot childSnapshotForPath:keyUserData];
FIRDataSnapshot *fireUserParameters = [snapshot childSnapshotForPath:keyToParameters];
FIRDataSnapshot *fireUserPhotos = [snapshot childSnapshotForPath:keyToPhotos];
FIRDataSnapshot *userIdent = fireUser.value[@"userID"];
FIRDataSnapshot *userName = fireUser.value[@"displayName"];
FIRDataSnapshot *userEmail = fireUser.value[@"email"];
FIRDataSnapshot *userPhoto = fireUser.value[@"photoURL"];
FIRDataSnapshot *dateOfBirth = fireUser.value[@"dateOfBirth"];
FIRDataSnapshot *age = fireUser.value[@"age"];
FIRDataSnapshot *location = fireUser.value[@"location"];
FIRDataSnapshot *gender = fireUser.value[@"gender"];
FIRDataSnapshot *online = fireUser.value[@"online"];
FIRDataSnapshot *parameters = fireUserParameters.value[@"parameters"];
FIRDataSnapshot *photos = fireUserPhotos.value[@"photos"];
user.uid = (NSString *)userIdent;
user.displayName = (NSString *)userName;
user.email = (NSString *)userEmail;
user.photoURL = (NSString *)userPhoto;
user.dateOfBirth = (NSString *)dateOfBirth;
user.age = (NSString *)age;
user.location = (NSString *)location;
user.gender = (NSString *)gender;
user.online = (NSString *)online;
user.parameters = (NSMutableDictionary *)parameters;
user.photos = (NSMutableArray *)photos;
}
I would be grateful for any provided assistance.
Upvotes: 0
Views: 112
Reputation: 131481
Is the first code you posted, the call to observeEventType, the code that is taking a long time to complete? And what does the configureController method do? Does it do any UIKit code, like setting up a view controller or view objects?
Does FireBase call it's completion handlers on a background thread? (You can either check the docs or test it by reading the value of Thread.isMainThread
inside your completion handler.
Upvotes: 1