我正在尝试使用Firebase Storage记录的示例代码:
// Reference to an image file in Firebase Storage
let reference = storageRef.child("images/stars.jpg")
// UIImageView in your ViewController
let imageView: UIImageView = self.imageView
// Placeholder image
let placeholderImage = UIImage(named: "placeholder.jpg")
// Load the image using SDWebImage
imageView.sd_setImage(with: reference, placeholderImage: placeholderImage)
在我的应用中如此改编:
func setImage(_ picid: Int32){
let imagesRefs = Constants.FirebaseConfig.storageRef.child("images/thumbs/\(getuid())/thumb_\(picid).jpg");
let placeholderImage = UIImage(named: "placeholder.jpg")
profilePicIV.sd_setImage(with: imagesRefs, placeholderImage: placeholderImage)
}
但是xcode找不到方法sd_setImage
所以我认为我必须使用pod'FirebaseUI / Storage'更新我的podfile但是在修改我的podfile后我得到了这个错误:
pod update
Update all pods
Updating local specs repositories
$ /usr/bin/git -C /Users/myname/.cocoapods/repos/master fetch origin --progress
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 18 (delta 12), reused 7 (delta 4), pack-reused 0
From https://github.com/CocoaPods/Specs
24df16553de..7cae8225fce master -> origin/master
$ /usr/bin/git -C /Users/myname/.cocoapods/repos/master rev-parse --abbrev-ref HEAD
master
$ /usr/bin/git -C /Users/myname/.cocoapods/repos/master reset --hard origin/master
HEAD is now at 7cae8225fce [Add] MixedRealityKit 0.1.6
Analyzing dependencies
[!] Unable to satisfy the following requirements:
- `TwitterCore (~> 2.8.0)` required by `Podfile`
- `TwitterCore (>= 3.0.0)` required by `TwitterKit (3.0.0)`
- `FirebaseUI` required by `Podfile`
Specs satisfying the `FirebaseUI` dependency were found, but they required a higher minimum deployment target.
我的pods文件是这样的,虽然我尝试过其他pod组合,但效果相同或更差:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.3'
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
target 'StrengthStandards' do
#Pods for StrengthStandards
pod 'Firebase'
pod 'Firebase/Core'
#pod 'Firebase/Auth'
#pod 'FirebaseUI/Google'
#pod 'Firebase/Crash'
#pod 'Firebase/RemoteConfig'
pod 'FirebaseUI'
pod 'Firebase/Database'
#pod 'FirebaseUI/Database'
#pod 'Firebase/Storage'
pod 'FirebaseUI/Storage'
pod 'TwitterCore', '~>2.8.0'
target 'StrengthStandardsTests' do
inherit! :search_paths
# Pods for testing
end
target 'StrengthStandardsUITests' do
inherit! :search_paths
# Pods for testing
end
end
我做错了什么?此外,我的xcode在No such module 'FirebaseAuthUI'
行上显示错误import FirebaseAuthUI
。
在此问题出现之前,我的Firebase数据库和Firebase Auth正在运行。
我在MacOS 10.12.6上使用Xcode 8.3.3和Swift 3
由于
PS:取得一些进展 - 现在我的podfile是:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.3'
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
target 'StrengthStandards' do
use_frameworks!
#Pods for StrengthStandards
#pod 'Firebase'
pod 'Firebase/Core'
#pod 'Firebase/Auth'
pod 'FirebaseUI/Auth'
pod 'FirebaseUI/Google'
#pod 'FirebaseUI/Google'
#pod 'Firebase/Crash'
#pod 'Firebase/RemoteConfig'
#pod 'FirebaseUI'
pod 'Firebase/Database'
#pod 'FirebaseUI/Database'
#pod 'Firebase/Storage'
pod 'FirebaseUI/Storage'
pod 'TwitterCore', '~>2.8.0'
target 'StrengthStandardsTests' do
inherit! :search_paths
# Pods for testing
end
target 'StrengthStandardsUITests' do
inherit! :search_paths
# Pods for testing
end
end
然而我不再得到依赖性问题,xcode现在告诉我方法调用
profilePicIV.sd_setImage(with: imagesRefs, placeholderImage: placeholderImage)
错了:
/Users/myname/Dev/IOSDev/StrengthStandards/StrengthStandards/Settings.swift:325:40: Cannot convert value of type 'StorageReference' to expected argument type 'URL?'
答案 0 :(得分:0)
现在似乎工作,但我承认我不确定它是否完全按照应该的方式完成。对于这里感兴趣的人,到目前为止我所拥有的是: Podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.3'
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
target 'StrengthStandards' do
use_frameworks!
pod 'Firebase/Core'
pod 'FirebaseUI/Auth'
pod 'FirebaseUI/Google'
pod 'Firebase/Database'
pod 'FirebaseUI/Storage'
pod 'TwitterCore', '~>2.8.0'
pod 'SDWebImage/Core'
target 'StrengthStandardsTests' do
inherit! :search_paths
# Pods for testing
end
target 'StrengthStandardsUITests' do
inherit! :search_paths
# Pods for testing
end
end
这是我的功能:
import SDWebImage
func setImage(_ picid: Int32){
let imagesRefs = Constants.FirebaseConfig.storageRef.child("images/thumbs/\(Constants.getUID())/thumb_\(picid).jpg");
imagesRefs.downloadURL { url, error in
if let error = error {
// Handle any errors
print("Error getting url for profile pic: \(error)")
} else {
// Get the download URL for 'images/stars.jpg'
let placeholderImage = UIImage(named: "placeholder.jpg")
self.profilePicIV.sd_setImage(with: url, placeholderImage: placeholderImage)
}
}
}