我使用Firebase作为我应用程序的后端。当用户完成身份验证时,他们将转到profile create页面。它显示来自facebook的用户配置文件图片。
我使用这段代码来显示
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配置文件图片”
这是我的相机和照片库的代码
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
}
发布于 2016-07-18 02:40:10
Firebase身份验证采用照片URL,因此用户的配置文件照片存在的公共位置。如果要允许用户上传新的配置文件照片,则必须找到存储照片的位置,然后将URL放入Firebase身份验证配置文件。
保存这种配置文件图片的一个地方是Firebase存储。请参阅如何从iOS上传图像上的文档,然后是存储在用户配置文件中的生成下载URL。
https://stackoverflow.com/questions/38427127
复制相似问题