0
嗨,我是來自臺灣的新手開發者。 我已經開始爲我的應用使用firebase(ios)存儲,並且我想使用ImageSliderShow來創建圖像滑塊視圖。我從Firebase獲取圖片網址後。我將url字符串附加到數組中,然後運行該應用程序。圖像滑塊視圖正常工作,但新圖像只顯示任何內容。然後我在追加到數組之前和之後打印了url字符串。它給了我兩個不同的字符串。這是我的代碼。Firebase存儲圖片網址無效
override func viewDidLoad() {
super.viewDidLoad()
let URLString = loadURL()
URLString.getURL(){
(result:String) in
self.ImageSliderView.backgroundColor = UIColor.white
self.ImageSliderView.slideshowInterval = 5.0
self.ImageSliderView.pageControlPosition = PageControlPosition.insideScrollView
self.ImageSliderView.pageControl.currentPageIndicatorTintColor = UIColor.lightGray
self.ImageSliderView.pageControl.pageIndicatorTintColor = UIColor.black
self.ImageSliderView.contentScaleMode = UIViewContentMode.scaleAspectFill
self.ImageSliderView.activityIndicator = DefaultActivityIndicator()
self.ImageSliderView.currentPageChanged = { page in
print("current page:", page)
}
print("Result: \(result)") ////print the result string before appended into array.
self.kingfisherSource.append(KingfisherSource(urlString: String(result))!)
print("alamoArray3: \(self.kingfisherSource[3].url)") ////print the result string after appended into array.
self.ImageSliderView.setImageInputs(self.kingfisherSource)
let recognizer = UITapGestureRecognizer(target: self, action: #selector(ResultViewController.didTap))
self.ImageSliderView.addGestureRecognizer(recognizer)
}
}
func didTap() {
let fullScreenController = ImageSliderView.presentFullScreenController(from: self)
// set the activity indicator for full screen controller (skipping the line will show no activity indicator)
fullScreenController.slideshow.activityIndicator = DefaultActivityIndicator(style: .white, color: nil)
}
的getURL功能:
class loadURL {
let storage = Storage.storage(url: "my-firebase-storage-bucket")
func getURL(completion:@escaping (_ result:String)->Void) {
self.storage.reference().child("images/breakfast/1/1.jpg").downloadURL { url, error in
if error != nil {
print("Firebase Image URL error: \(String(describing: error))")
} else {
print("Firebase Image URL: \(String(describing: url!))")
completion("\(String(describing: url))")
}
}
}
輸出:
Firebase Image URL: https://firebasestorage.googleapis.com/v0/b/my-firebase-storage-bucket/o/images%2Fbreakfast%2F1%2F1.jpg?alt=media&token=15ee8094-ac50-4e93-adc0-200793181bfc
Result: Optional(https://firebasestorage.googleapis.com/v0/b/my-firebase-storage-bucket/o/images%2Fbreakfast%2F1%2F1.jpg?alt=media&token=15ee8094-ac50-4e93-adc0-200793181bfc)
alamoArray3: Optional(https://firebasestorage.googleapis.com/v0/b/my-firebase-storage-bucket/o/images%2Fbreakfast%2F1%2F1.jpg?alt=m ... 3181bfc)
第三輸出只是奇怪...是否有可能是編碼的問題? 我對我的壞英語表示歉意。