AppDelegate.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "AppDelegate.h"
  17. #import "FirebaseCore.h"
  18. #import "FirebaseFirestore.h"
  19. @interface AppDelegate ()
  20. @property(weak) IBOutlet NSWindow *window;
  21. @end
  22. @implementation AppDelegate
  23. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  24. // create a firestore db
  25. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info"
  26. ofType:@"plist"];
  27. FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
  28. [FIRApp configureWithOptions:options];
  29. FIRFirestore *db = [FIRFirestore firestore];
  30. // do the timestamp fix
  31. FIRFirestoreSettings *settings = db.settings;
  32. settings.timestampsInSnapshotsEnabled = true;
  33. db.settings = settings;
  34. // create a doc
  35. FIRDocumentReference *docRef = [[db collectionWithPath:@"junk"] documentWithPath:@"test_doc"];
  36. NSDictionary *data = @{@"msg" : @"hello"};
  37. [docRef setData:data
  38. completion:^(NSError *_Nullable error) {
  39. if (error != nil) {
  40. NSLog(@"created error: %@", error);
  41. } else {
  42. NSLog(@"Yay!");
  43. }
  44. }];
  45. }
  46. - (void)applicationWillTerminate:(NSNotification *)aNotification {
  47. // Insert code here to tear down your application
  48. }
  49. @end