Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve data from firebase in objective c

I'm trying to retrieve data from firebase and I an using the guide given by firebase but I am not able to create the reference with my firebase database.

FIRDatabaseReference * ref = [[FIRDatabase alloc]
    referenceFromURL:@"https://project-8326407164650950213.firebaseio.com"];
NSLog(@"%@",ref);

I am using this code to create the reference with my database but app crash.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'

I am new in iOS and first time using firebase. Please tell me the solution as I am going according to firebase guide.

like image 210
Muhammad Salman Avatar asked Nov 29 '25 14:11

Muhammad Salman


2 Answers

I'm no firebase expert, but when you're working with a class in Obj-C, you'll either invoke its class methods (e.g. [FIRDatabase database]), or you'll first allocate and initialize it ([[FIRDatabase alloc] <an initializer>]), and secondly use an instance method on the instance.

In your code sample above, I see an alloc without an initializer, which makes me think you're missing something.

If I look at the iOS quick start, I see a call to initWithURL, which is one of the initializers.

like image 53
Geoffrey Wiseman Avatar answered Dec 01 '25 05:12

Geoffrey Wiseman


    Firebase *messagePath = [[Firebase alloc] initWithUrl:[NSString stringWithFormat:@"%@%@%@", MAIN_URL,MESSAGES_DIRECTORY,conversationId]];
[[messagePath queryLimitedToLast:10] observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
    NSMutableArray *messages = [[NSMutableArray alloc] init];
    [messages addObject:snapshot.value];
    observingBlock(true,messages);
}];
  • Here is the code with you can get the data and value of the node. First make url till your node.
  • Still you have any problem just add comment here. now a days working on Firebase chat in swift.
like image 37
Jecky Avatar answered Dec 01 '25 05:12

Jecky