首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >快速显示的firebase photoUrl不能用图像选择器替换图像

快速显示的firebase photoUrl不能用图像选择器替换图像
EN

Stack Overflow用户
提问于 2016-07-18 00:13:00
回答 1查看 493关注 0票数 0

我使用Firebase作为我应用程序的后端。当用户完成身份验证时,他们将转到profile create页面。它显示来自facebook的用户配置文件图片。

我使用这段代码来显示

代码语言:javascript
运行
复制
func displayProfilePic(user: FIRUser?){

let photoURL = user?.photoURL
struct last {
  static var photoURL: NSURL? = nil
}
last.photoURL = photoURL;  // to prevent earlier image overwrites later one.
if let photoURL = photoURL {
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
    let data = NSData.init(contentsOfURL: photoURL)
    if let data = data {
      let image = UIImage.init(data: data)
      dispatch_async(dispatch_get_main_queue(), {
        if (photoURL == last.photoURL) {
          self.profilePic.image = image
        }
      })
    }
  })
} else {
  profilePic.image = UIImage.init(named: "DefaultPic")
}

但是,我也允许用户通过相机或照片库来选择自己的个人资料图片。当用户选择自己的图像时,它将显示选中的图像1到2秒,并显示回脸谱个人资料图片。的意思是,“被选中的图像不能取代facebook配置文件图片”

这是我的相机和照片库的代码

代码语言:javascript
运行
复制
func openGallary(){

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
  print("Pick Photo")

  self.imagePicker.delegate = self
  self.imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
  self.imagePicker.allowsEditing = true
  self.presentViewController(self.imagePicker, animated: true, completion: nil)
}
}

func openCamera(){
if(UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
  self.imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
  self.imagePicker.allowsEditing = true
  self.presentViewController(self.imagePicker, animated: true, completion: nil)

}else{
  print("you got no camara")
}
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismissViewControllerAnimated(true, completion: { () -> Void in

})
profilePic.image = image
}
EN

回答 1

Stack Overflow用户

发布于 2016-07-18 02:40:10

Firebase身份验证采用照片URL,因此用户的配置文件照片存在的公共位置。如果要允许用户上传新的配置文件照片,则必须找到存储照片的位置,然后将URL放入Firebase身份验证配置文件。

保存这种配置文件图片的一个地方是Firebase存储。请参阅如何从iOS上传图像上的文档,然后是存储在用户配置文件中的生成下载URL

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38427127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档