ios - 用户注册期间,Firebase将镜像上传到存储

标签 ios objective-c firebase firebase-storage

我是Firebase的新手,我一直在关注他们的文档here
但是,我尝试过的任何方法似乎都无效。

我正在尝试做的是:

1)注册用户 -Works

2)在注册过程中让用户选择个人资料图片-不起作用。

代码:

- (void) registerNewUser:(FIRUser *)user

{
    FIRUser *currentUser = [FIRAuth auth].currentUser;
    NSString *email = emailAddressTxtField.text;
    NSString *password = passwordTxtField.text;
    NSString *username = usernameTxtField.text;
    [[FIRAuth auth]
     createUserWithEmail:email
     password:password
     completion:^(FIRUser *_Nullable user,
                  NSError *_Nullable error)
     {
         if (error)
         {
             NSLog(@"%@", error.localizedDescription);
             return;
         }
         else
         {
             ////ASSIGN NEW USER THEIR NAME////
             self.databaseRef = [[FIRDatabase database] reference];
             [[[databaseRef child:@"users"] child:user.uid]
              setValue:@{@"name": username}];
         }
     }];
    ////ESTABLISHED A USER, SO LET'S ASSIGN THEIR PIC TO THEM////
    if (profilePicImageView.image)
    {
        FIRStorageReference *profilePicRef = [[storageRef child:@"images/profilePicture.jpg"] child:currentUser.uid];
        FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] init];
        metadata.contentType = @"image/jpeg";
        NSData *imageData = UIImageJPEGRepresentation(self.profilePicImageView.image, 0.8);
        NSLog(@"metadata from image: %@", metadata);

        [profilePicRef putData:imageData metadata:metadata completion:^(FIRStorageMetadata *metadata, NSError *error)
         {
             if (error != nil)
             {
                 NSString *profileImageURL = metadata.downloadURL.absoluteString;
                 NSLog(@"Profile Image URL from image: %@", profileImageURL);
                 [ProgressHUD showSuccess:[NSString stringWithFormat:@"%@ Successfully Registered!!", username]];
                 [self.segmentedLoginRegister setSelectedSegmentIndex:0];
                 [self checkSegmentedControl];
                 [ProgressHUD showSuccess:[NSString stringWithFormat:@"Welcome %@!", username]];
             }
             else
             {
                 NSLog(@"Failed to Register User with profile image");
             }
         }];
    }
}

附加信息:

照片仅来自用户设备的相机胶卷
调试区域打印:

[通用]创建未知类型的图像格式是错误的

最佳答案

我的猜测是profilePicImageView.image实际上不包含有效的图像对象。

关于ios - 用户注册期间,Firebase将镜像上传到存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40137707/

相关文章:

ios - 具有居中 View 的基本快速布局,其中包含程序中的标签和文本

objective-c - 在 Objective-C 中使用类别的私有(private)方法 : calling super from a subclass

ios - 使用适当的日期设置 UIPickerview 选择时出现奇怪的错误; selectRow 导致错误

Android 构建不起作用(在模块中发现重复的类 com.google.android.gms.internal.measurement.zzbt)

ios - 从模态视图返回后使用手势识别器关闭 UISearchBar 的键盘

ios - UIPageViewController Swift 中的当前页面索引

ios - 使用 iOS Spotify SDK 在给定的开始时间启动 Spotify 轨道播放?

ios - 如何从完成 block 安全地推送 View Controller ?

android - 使用 Xamarin Forms 设置 Android 和 iOS 的推送通知角标(Badge)时遇到问题

javascript - Vuejs 异步请求完成后显示结果