DeBug Day 26

修正Bug日

  • [ ] 修正首页的排版问题
  • [ ] 修正书本细节页面的排版问题
  • [ ] 修正新增照片到FireBase

AutoLayout修正结果

https://i.imgur.com/c0cFIck.png

https://i.imgur.com/JrHcRui.png

FireBase照片上传修正流程

let bookItemRef = self.ref!.child(values.booktitle.lowercased())
let storageImageRef = Storage.storage().reference().child("BookRentImage").child("\(values.booktitle).jpg")

let uploadTask = storageImageRef.putData(self.ImageData!,metadata:nil){(data,error) in
	if error != nil{
		print(error.localizedDescription)
		return
		}
	// KVO应用
	uploadTask.observe(.success, handler:{(snapshot) in 
		// 下载刚刚上传图片的URL
		storageImageRef.downloadRef{(url,error) in 
			// 要先让error 被指派为error,才能使用error
			if let error = error{
					print("失败",error.localizedDescription)
			}else{
				// absoluteString完整的网域名称
			if let imageFileURL = url?.absoluteString{
					// 确认是否为正确的网址
					print("photoImageUploadSuccess:",imageFileURL)
			}
	// 新增bookImage的url上去,因为如果按下上传 要传url要等到上传结束
	bookItemRef.child(values.booktitle).setValue(bookItem.ImagetoDictionary(),withCompletionBlock:{ (error,ref) in 
		if error = nil{
			let alertController = UIAlertControler(title:"Upload Image Success!",message:"Congradulation",preferredStyle: .alert)
			let alertAction = UIAlertAction(title:"OK", style:.cancel, handler:nil)
			alertController.addAction(alertAction)
			self.present(alertControler,animated:true, completion: nil)
			}
	})
	
	
	bookItem = Book(booktitle: values.booktitle, bookauthors: values.bookauthors, bookISBN: values.bookISBN, bookimage: self.uploadURL)
	// 新增Book的等等资训
	bookItemRef.setValue(bookItem.toDictionary(),withCompletionBlock:{ (error,ref) in
	if error == nil {
	let alertController = UIAlertController(title: "Upload Success", message: "Congradulation", preferredStyle: .alert)
	let alertAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
            
	alertController.addAction(alertAction)
	self.present(alertController, animated: true, completion: nil)
	}})

		

参考网址

Firebase教学:如何实作上传图片功能与远端存取

使用Firebase Storage、Firebase Realtime Database上传与下载图片 Swift5.3,Xcode 12,iOS 14

Download files with Cloud Storage on iOS | Firebase


<<:  30天打造品牌特色电商网站 Day.16 微互动设计按钮实作(2)

>>:  Day 15 - 介绍 PBR

【Day 10】Concurrency control in apps

todos: 还在出去玩,之後补上演算法 pesudocode + comments 8.2 提到的...

用这9种技巧让你的部落格有个好名字

一、前言 经营部落格,会是一个长期的网路事业,在初期有许多部分我认为就应该思考好,在整个经营路上才...

[Part 3 ] Vue.js 的精随-元件 provide/inject

利用 provide & inject 机制,父元件当作所有其子元件的 provider,无...

Day2 在繁忙的时间上,到底该如何规划时间学习呢?

大家好,我是乌木白,之前在自我介绍时!有和大家说过我目前是一个学生,平常也是需要打工,所以在一天之...

【Day 15】Google Apps Script - API 篇 - Document Service - 文件服务范例-新增内容

来练习帮 Google 文件增加一点内容吧。 今日要点: 》Document Service 文件...