From 499758296d20cf5a1fd0bcd7e4009f374062358e Mon Sep 17 00:00:00 2001 From: Ibrahim Ulukaya Date: Mon, 7 Mar 2016 15:08:57 -0500 Subject: [PATCH] add storage to firebase codelab ios Change-Id: I26dde8156c8702970ac44800f7ecc5721daaeda2 --- .../FriendlyChatObjC/FCViewController.m | 51 +++++++- .../FriendlyChatObjC/Main.storyboard | 96 ++++++++------- .../Contents.json | 6 +- .../ic_add_a_photo.png | Bin 0 -> 236 bytes .../ic_add_a_photo_2x.png | Bin 0 -> 429 bytes .../ic_add_a_photo_3x.png | Bin 0 -> 637 bytes .../ic_camera.imageset/ic_camera.png | Bin 380 -> 0 bytes .../ic_camera.imageset/ic_camera_2x.png | Bin 745 -> 0 bytes .../ic_camera.imageset/ic_camera_3x.png | Bin 1079 -> 0 bytes .../ic_photo_camera.png | Bin 236 -> 0 bytes .../ic_photo_camera_2x.png | Bin 430 -> 0 bytes .../ic_photo_camera_3x.png | Bin 643 -> 0 bytes .../project.pbxproj | 57 ++++++++- .../Base.lproj/Main.storyboard | 96 ++++++++------- .../FriendlyChatSwift/BridgingHeader.h | 17 +++ .../FriendlyChatSwift/FCViewController.swift | 47 +++++++- .../ic_add_a_photo.imageset}/Contents.json | 6 +- .../ic_add_a_photo.png | Bin 0 -> 236 bytes .../ic_add_a_photo_2x.png | Bin 0 -> 429 bytes .../ic_add_a_photo_3x.png | Bin 0 -> 637 bytes .../project.pbxproj | 57 +++++++++ ios/objc/FriendlyChatObjC/Constants.h | 1 + ios/objc/FriendlyChatObjC/Constants.m | 1 + ios/objc/FriendlyChatObjC/FCViewController.m | 114 ++++++++++++++---- ios/objc/FriendlyChatObjC/Main.storyboard | 25 +++- .../FriendlyChatObjC/SignInViewController.m | 4 +- ios/objc/Podfile | 2 +- .../ic_add_a_photo.imageset/Contents.json | 23 ++++ .../ic_add_a_photo.png | Bin 0 -> 236 bytes .../ic_add_a_photo_2x.png | Bin 0 -> 429 bytes .../ic_add_a_photo_3x.png | Bin 0 -> 637 bytes .../project.pbxproj | 61 +++++++++- .../Base.lproj/Main.storyboard | 96 ++++++++------- ios/swift/FriendlyChatSwift/BridgingHeader.h | 17 +++ ios/swift/FriendlyChatSwift/Constants.swift | 1 + .../FriendlyChatSwift/FCViewController.swift | 96 ++++++++++++--- ios/swift/Podfile | 2 +- .../ic_add_a_photo.imageset/Contents.json | 23 ++++ .../ic_add_a_photo.png | Bin 0 -> 236 bytes .../ic_add_a_photo_2x.png | Bin 0 -> 429 bytes .../ic_add_a_photo_3x.png | Bin 0 -> 637 bytes ios/swift/shared/LaunchScreen.xib | 4 +- 42 files changed, 713 insertions(+), 190 deletions(-) rename ios-starter/objc-starter/shared/Images.xcassets/{ic_camera.imageset => ic_add_a_photo.imageset}/Contents.json (70%) create mode 100644 ios-starter/objc-starter/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo.png create mode 100644 ios-starter/objc-starter/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo_2x.png create mode 100644 ios-starter/objc-starter/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo_3x.png delete mode 100644 ios-starter/objc-starter/shared/Images.xcassets/ic_camera.imageset/ic_camera.png delete mode 100644 ios-starter/objc-starter/shared/Images.xcassets/ic_camera.imageset/ic_camera_2x.png delete mode 100644 ios-starter/objc-starter/shared/Images.xcassets/ic_camera.imageset/ic_camera_3x.png delete mode 100644 ios-starter/objc-starter/shared/Images.xcassets/ic_photo_camera.imageset/ic_photo_camera.png delete mode 100644 ios-starter/objc-starter/shared/Images.xcassets/ic_photo_camera.imageset/ic_photo_camera_2x.png delete mode 100644 ios-starter/objc-starter/shared/Images.xcassets/ic_photo_camera.imageset/ic_photo_camera_3x.png create mode 100644 ios-starter/swift-starter/FriendlyChatSwift/BridgingHeader.h rename ios-starter/{objc-starter/shared/Images.xcassets/ic_photo_camera.imageset => swift-starter/shared/Images.xcassets/ic_add_a_photo.imageset}/Contents.json (69%) create mode 100644 ios-starter/swift-starter/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo.png create mode 100644 ios-starter/swift-starter/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo_2x.png create mode 100644 ios-starter/swift-starter/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo_3x.png create mode 100644 ios/objc/shared/Images.xcassets/ic_add_a_photo.imageset/Contents.json create mode 100644 ios/objc/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo.png create mode 100644 ios/objc/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo_2x.png create mode 100644 ios/objc/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo_3x.png create mode 100644 ios/swift/FriendlyChatSwift/BridgingHeader.h create mode 100644 ios/swift/shared/Images.xcassets/ic_add_a_photo.imageset/Contents.json create mode 100644 ios/swift/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo.png create mode 100644 ios/swift/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo_2x.png create mode 100644 ios/swift/shared/Images.xcassets/ic_add_a_photo.imageset/ic_add_a_photo_3x.png diff --git a/ios-starter/objc-starter/FriendlyChatObjC/FCViewController.m b/ios-starter/objc-starter/FriendlyChatObjC/FCViewController.m index 4d7be24c4..29340662a 100644 --- a/ios-starter/objc-starter/FriendlyChatObjC/FCViewController.m +++ b/ios-starter/objc-starter/FriendlyChatObjC/FCViewController.m @@ -18,6 +18,7 @@ #import "Constants.h" #import "FCViewController.h" +#import "FirebaseStorage.h" @import FirebaseDatabase; @import FirebaseApp; @import FirebaseAuth; @@ -27,10 +28,9 @@ @import Firebase.CrashReporting; @interface FCViewController () { +UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate> { int _msglength; FirebaseHandle _refHandle; - UInt32 _userInt; } @property(nonatomic, weak) IBOutlet UITextField *textField; @@ -41,6 +41,7 @@ @interface FCViewController () *messages; +@property (strong, nonatomic) FIRStorage *storageRef; @end @@ -57,14 +58,13 @@ - (IBAction)didPressCrash:(id)sender { - (void)viewDidLoad { [super viewDidLoad]; - _userInt = arc4random(); _msglength = 10; _messages = [[NSMutableArray alloc] init]; [self loadAd]; [_clientTable registerClass:UITableViewCell.self forCellReuseIdentifier:@"tableViewCell"]; [self fetchConfig]; - + [self configureStorage]; } - (void)loadAd { @@ -73,6 +73,9 @@ - (void)loadAd { - (void)fetchConfig { } +- (void)configureStorage { +} + - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(nonnull NSString *)string { NSString *text = textField.text; if (!text) { @@ -102,9 +105,49 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(n // UITextViewDelegate protocol methods - (BOOL)textFieldShouldReturn:(UITextField *)textField { + NSMutableDictionary *data = [[NSMutableDictionary alloc] init]; + data[MessageFieldstext] = textField.text; + [self sendMessage:data]; + textField.text = @""; return YES; } +- (void)sendMessage:(NSDictionary *)data { +} + +# pragma mark - Image Picker + +- (IBAction)didTapAddPhoto:(id)sender { + UIImagePickerController * picker = [[UIImagePickerController alloc] init]; + picker.delegate = self; + if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { + picker.sourceType = UIImagePickerControllerSourceTypeCamera; + } else { + picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; + } + + [self presentViewController:picker animated:YES completion:NULL]; +} + +- (void)imagePickerController:(UIImagePickerController *)picker +didFinishPickingMediaWithInfo:(NSDictionary *)info { + [picker dismissViewControllerAnimated:YES completion:NULL]; + + NSURL *referenceUrl = info[UIImagePickerControllerReferenceURL]; + PHFetchResult* assets = [PHAsset fetchAssetsWithALAssetURLs:@[referenceUrl] options:nil]; + PHAsset *asset = [assets firstObject]; + [asset requestContentEditingInputWithOptions:nil + completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) { + NSString *imageFile = [contentEditingInput.fullSizeImageURL absoluteString]; + NSString *fileName = [[AppState sharedInstance].displayName stringByAppendingString:[referenceUrl lastPathComponent]]; + } + ]; +} + +- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { + [picker dismissViewControllerAnimated:YES completion:NULL]; +} + - (IBAction)signOut:(UIButton *)sender { [AppState sharedInstance].signedIn = false; [self performSegueWithIdentifier:SeguesFpToSignIn sender:nil]; diff --git a/ios-starter/objc-starter/FriendlyChatObjC/Main.storyboard b/ios-starter/objc-starter/FriendlyChatObjC/Main.storyboard index 93889a802..3db78fcbe 100644 --- a/ios-starter/objc-starter/FriendlyChatObjC/Main.storyboard +++ b/ios-starter/objc-starter/FriendlyChatObjC/Main.storyboard @@ -19,10 +19,10 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -145,7 +144,7 @@ -