在 4.0.0 版的 Firebase iOS SDK for Swift 中,我们进行了一些更改,以遵循 Swift API 设计准则中的命名规范。如需修正更新应用的 Firebase iOS SDK 版本时可能收到的任何错误或警告,请按照此迁移指南中的步骤操作。
新版本中的更改
在所有 Firebase 产品中,Swift SDK 都进行了以下更改:
- 移除了所有常量、协议、类、枚举和类型定义的名称中的
FIR
前缀。 - 将
FIRApp
重命名为FirebaseApp
。 - 将
FIROptions
重命名为FirebaseOptions
。
如需查看变更的完整列表,请参阅“详细变更列表”部分。
解决错误
要解决这些更改导致的错误,最好的方法是在 Xcode 中使用“Fix-it”对话框。
- 当您在 Xcode 工作区中打开更新后的项目时,问题导航器中会显示因更改命名而产生的错误。
- 点击相应错误,然后按照“Fix-it”对话框中的建议解决该错误。
解决命名冲突
如需解决命名冲突,请使用模块提供的命名空间。例如,对于 FIRUser
(现在是 User
),您可能需要区分 User
类/结构体和 Firebase User
类。
@import Firebase ... var firebaseUser: Firebase.User?
详细的更改列表
分析
之前 | 新 |
---|---|
函数 | |
FIRAnalytics | |
logEvent(withName:parameters:) |
logEvent(_:parameters:) |
之前的用法:
FIRAnalytics.logEvent(withName: "com.myapp.appStart", parameters: nil) Analytics.logEvent("com.myapp.appStart", parameters: nil) | |
setUserPropertyString(_:forName:) | setUserProperty(_:forName:) |
之前的用法:
FIRAnalytics.setUserPropertyString("mechanic", forName: "job") Analytics.setUserProperty("mechanic", forName: "job") | |
类 | |
FIRAnalytics | Analytics |
常量 | |
FIRAnalyticsEventAddPaymentInfo | AnalyticsEventAddPaymentInfo |
FIRAnalyticsEventAddToCart | AnalyticsEventAddToCart |
FIRAnalyticsEventAddToWishlist | AnalyticsEventAddToWishlist |
FIRAnalyticsEventAppOpen | AnalyticsEventAppOpen |
FIRAnalyticsEventBeginCheckout | AnalyticsEventBeginCheckout |
FIRAnalyticsEventCampaignDetails | AnalyticsEventCampaignDetails |
FIRAnalyticsEventCheckoutProgress | AnalyticsEventCheckoutProgress |
FIRAnalyticsEventEarnVirtualCurrency | AnalyticsEventEarnVirtualCurrency |
FIRAnalyticsEventEcommercePurchase | AnalyticsEventEcommercePurchase |
FIRAnalyticsEventGenerateLead | AnalyticsEventGenerateLead |
FIRAnalyticsEventJoinGroup | AnalyticsEventJoinGroup |
FIRAnalyticsEventLevelUp | AnalyticsEventLevelUp |
FIRAnalyticsEventLogin | AnalyticsEventLogin |
FIRAnalyticsEventPostScore | AnalyticsEventPostScore |
FIRAnalyticsEventPresentOffer | AnalyticsEventPresentOffer |
FIRAnalyticsEventPurchaseRefund | AnalyticsEventPurchaseRefund |
FIRAnalyticsEventRemoveFromCart | AnalyticsEventRemoveFromCart |
FIRAnalyticsEventSearch | AnalyticsEventSearch |
FIRAnalyticsEventSelectContent | AnalyticsEventSelectContent |
FIRAnalyticsEventSetCheckoutOption | AnalyticsEventSetCheckoutOption |
FIRAnalyticsEventShare | AnalyticsEventShare |
FIRAnalyticsEventSignUp | AnalyticsEventSignUp |
FIRAnalyticsEventSpendVirtualCurrency | AnalyticsEventSpendVirtualCurrency |
FIRAnalyticsEventTutorialBegin | AnalyticsEventTutorialBegin |
FIRAnalyticsEventTutorialComplete | AnalyticsEventTutorialComplete |
FIRAnalyticsEventUnlockAchievement | AnalyticsEventUnlockAchievement |
FIRAnalyticsEventViewItem | AnalyticsEventViewItem |
FIRAnalyticsEventViewItemList | AnalyticsEventViewItemList |
FIRAnalyticsEventViewSearchResults | AnalyticsEventViewSearchResults |
FIRAnalyticsParameterAchievementID | AnalyticsParameterAchievementID |
FIRAnalyticsParameterAdNetworkClickID | AnalyticsParameterAdNetworkClickID |
FIRAnalyticsParameterAffiliation | AnalyticsParameterAffiliation |
FIRAnalyticsParameterCampaign | AnalyticsParameterCampaign |
FIRAnalyticsParameterCharacter | AnalyticsParameterCharacter |
FIRAnalyticsParameterCheckoutStep | AnalyticsParameterCheckoutStep |
FIRAnalyticsParameterCheckoutOption | AnalyticsParameterCheckoutOption |
FIRAnalyticsParameterContent | AnalyticsParameterContent |
FIRAnalyticsParameterContentType | AnalyticsParameterContentType |
FIRAnalyticsParameterCoupon | AnalyticsParameterCoupon |
FIRAnalyticsParameterCreativeName | AnalyticsParameterCreativeName |
FIRAnalyticsParameterCreativeSlot | AnalyticsParameterCreativeSlot |
FIRAnalyticsParameterCurrency | AnalyticsParameterCurrency |
FIRAnalyticsParameterDestination | AnalyticsParameterDestination |
FIRAnalyticsParameterEndDate | AnalyticsParameterEndDate |
FIRAnalyticsParameterFlightNumber | AnalyticsParameterFlightNumber |
FIRAnalyticsParameterGroupID | AnalyticsParameterGroupID |
FIRAnalyticsParameterIndex | AnalyticsParameterIndex |
FIRAnalyticsParameterItemBrand | AnalyticsParameterItemBrand |
FIRAnalyticsParameterItemCategory | AnalyticsParameterItemCategory |
FIRAnalyticsParameterItemID | AnalyticsParameterItemID |
FIRAnalyticsParameterItemLocationID | AnalyticsParameterItemLocationID |
FIRAnalyticsParameterItemName | AnalyticsParameterItemName |
FIRAnalyticsParameterItemList | AnalyticsParameterItemList |
FIRAnalyticsParameterItemVariant | AnalyticsParameterItemVariant |
FIRAnalyticsParameterLevel | AnalyticsParameterLevel |
FIRAnalyticsParameterLocation | AnalyticsParameterLocation |
FIRAnalyticsParameterMedium | AnalyticsParameterMedium |
FIRAnalyticsParameterNumberOfNights | AnalyticsParameterNumberOfNights |
FIRAnalyticsParameterNumberOfPassengers | AnalyticsParameterNumberOfPassengers |
FIRAnalyticsParameterNumberOfRooms | AnalyticsParameterNumberOfRooms |
FIRAnalyticsParameterOrigin | AnalyticsParameterOrigin |
FIRAnalyticsParameterPrice | AnalyticsParameterPrice |
FIRAnalyticsParameterQuantity | AnalyticsParameterQuantity |
FIRAnalyticsParameterScore | AnalyticsParameterScore |
FIRAnalyticsParameterSearchTerm | AnalyticsParameterSearchTerm |
FIRAnalyticsParameterShipping | AnalyticsParameterShipping |
FIRAnalyticsParameterSignUpMethod | AnalyticsParameterSignUpMethod |
FIRAnalyticsParameterSource | AnalyticsParameterSource |
FIRAnalyticsParameterStartDate | AnalyticsParameterStartDate |
FIRAnalyticsParameterTax | AnalyticsParameterTax |
FIRAnalyticsParameterTerm | AnalyticsParameterTerm |
FIRAnalyticsParameterTransactionID | AnalyticsParameterTransactionID |
FIRAnalyticsParameterTravelClass | AnalyticsParameterTravelClass |
FIRAnalyticsParameterValue | AnalyticsParameterValue |
FIRAnalyticsParameterVirtualCurrencyName | AnalyticsParameterVirtualCurrencyName |
FIRAnalyticsUserPropertySignUpMethod | AnalyticsUserPropertySignUpMethod |
身份验证
之前 | 新 |
---|---|
函数 | |
FIRAuth.h | |
init?(app:) | auth(app:) |
之前的用法:
let auth = FIRAuth(app: myApp) let auth = Auth.auth(app: myApp) | |
FIRUser.h | |
updateEmail(_:completion:) | updateEmail(to:completion:) |
之前的用法:
user.updateEmail("firebase_rox42@gmail.com") { error in // Check for error } user.updateEmail(to: "firebase_rox42@gmail.com") { error in // Check for error } | |
updatePassword(_:completion:) |
updatePassword(to:completion:) |
之前的用法:
user.updatePassword("hunter2") { error in // Check for error } user.updatePassword(to: "hunter2") { error in // Check for error } | |
profileChangeRequest() |
createProfileChangeRequest() |
之前的用法:
let request = user.profileChangeRequest() let request = user.createProfileChangeRequest() | |
getTokenWithCompletion(_:) |
getToken(completion:) |
之前的用法:
user.getTokenWithCompletion() { token, error in // Handle token or error here } user.getToken() { token, error in // Handle token or error here } | |
类 | |
FIRAdditionalUserInfo | AdditionalUserInfo |
FIRActionCodeInfo | ActionCodeInfo |
FIRAuth | Auth |
FIRAuthCredential | AuthCredential |
FIRAuthDataResult | AuthDataResult |
FIRAuthErrors | AuthErrors |
FIRSecureTokenService | SecureTokenService |
FIRUser | User |
FIRUserProfileChangeRequest | UserProfileChangeRequest |
FIRUserInfo | UserInfo |
FIREmailAuthProvider | EmailAuthProvider |
FIRFacebookAuthProvider | FacebookAuthProvider |
FIRGitHubAuthProvider | GitHubAuthProvider |
FIRGoogleAuthProvider | GoogleAuthProvider |
FIROAuthProvider | OAuthProvider |
FIRTwitterAuthProvider | TwitterAuthProvider |
常量 | |
FIRAuthErrorDomain | AuthErrorDomain |
FIRAuthErrorNameKey | AuthErrorNameKey |
FIREmailAuthProviderID | EmailAuthProviderID |
FIRFacebookAuthProviderID | FacebookAuthProviderID |
FIRGitHubAuthProviderID | GitHubAuthProviderID |
FIRGoogleAuthProviderID | GoogleAuthProviderID |
FIRTwitterAuthProviderID | TwitterAuthProviderID |
FIRAuthStateDidChange | AuthStateDidChange |
类型声明 | |
FIRAuthStateDidChangeListenerHandle | AuthStateDidChangeListenerHandle |
FIRAuthStateDidChangeListenerBlock | AuthStateDidChangeListenerBlock |
FIRAuthDataResultCallback | AuthDataResultCallback |
FIRAuthResultCallback | AuthResultCallback |
FIRProviderQueryCallback | ProviderQueryCallback |
FIRSendPasswordResetCallback | SendPasswordResetCallback |
FIRConfirmPasswordResetCallback | ConfirmPasswordResetCallback |
FIRVerifyPasswordResetCodeCallback | VerifyPasswordResetCodeCallback |
FIRApplyActionCodeCallback | ApplyActionCodeCallback |
FIRVerificationResultCallback | VerificationResultCallback |
枚举 | |
FIRActionDataKey | ActionDataKey |
FIRActionCodeOperation | ActionCodeOperation |
FIRAuthErrorCode | AuthErrorCode |
核心
之前 | 新 |
---|---|
函数 | |
FIRAnalyticsConfiguration.sharedInstance() | AnalyticsConfiguration.shared() |
FIRApp.configure(withName:options:) |
FirebaseApp.configure(name:options:) |
之前的用法:
FIRApp.configure(withName: "myCustomApp", options: customOptions) FirebaseApp.configure(name: "myCustomApp", options: customOptions) | |
FIRApp.defaultApp() |
FirebaseApp.app() |
FIRApp.init?(named:) |
FirebaseApp.app(name:) |
之前的用法:
let app = FIRApp(named: "myCustomApp") let app = FirebaseApp.app(name: "myCustomApp") | |
FIRApp.allApps() |
FirebaseApp.allApps |
之前的用法:
for app in FIRApp.allApps() { print("App name: \(app.name)") } for app in FirebaseApp.allApps { print("App name: \(app.name)") } | |
FIRConfiguration.sharedInstance() | FirebaseConfiguration.shared() |
FIROptions.default() | FirebaseOptions.defaultOptions() |
属性 | |
FIROptions | |
GCMSenderID | gcmSenderID |
类 | |
FIRAnalyticsConfiguration | AnalyticsConfiguration |
FIRApp | FirebaseApp |
FIRConfiguration | FirebaseConfiguration |
FIROptions | FirebaseOptions |
类型声明 | |
FIRAppVoidBoolCallback | FirebaseAppVoidBoolCallback |
枚举 | |
FIRLoggerLevel | FirebaseLoggerLevel |
崩溃
之前 | 新 |
---|---|
函数 | |
FIRCrashMessage(_:) |
FirebaseCrashMessage(_:) |
数据库
之前 | 新 |
---|---|
属性 | |
FIRDatabase.h | |
persistenceEnabled | isPersistenceEnabled |
类 | |
FIRDataSnapshot | DataSnapshot |
FIRDatabase | Database |
FIRDatabaseQuery | DatabaseQuery |
FIRDatabaseReference | DatabaseReference |
FIRMutableData | MutableData |
FIRServerValue | ServerValue |
FIRTransactionResult | TransactionResult |
类型声明 | |
FIRDatabaseHandle | DatabaseHandle |
枚举 | |
FIRDataEventType | DataEventType |
Dynamic Links
之前 | 新 |
---|---|
函数 | |
// FIRDynamicLinks.h | |
dynamicLink(fromUniversalLinkURL:) | dynamicLink(fromUniversalLink:) |
类 | |
FIRDynamicLink | DynamicLink |
FIRDLRetrievalDelegate | DLRetrievalDelegate |
FIRDynamicLinks | DynamicLinks |
FIRDynamicLinkGoogleAnalyticsParameters | DynamicLinkGoogleAnalyticsParameters |
FIRDynamicLinkIOSParameters | DynamicLinkIOSParameters |
FIRDynamicLinkItunesConnectAnalyticsParameters | DynamicLinkItunesConnectAnalyticsParameters |
FIRDynamicLinkAndroidParameters | DynamicLinkAndroidParameters |
FIRDynamicLinkSocialMetaTagParameters | DynamicLinkSocialMetaTagParameters |
FIRDynamicLinkNavigationInfoParameters | DynamicLinkNavigationInfoParameters |
FIRDynamicLinkComponentsOptions | DynamicLinkComponentsOptions |
FIRDynamicLinkComponents | DynamicLinkComponents |
类型声明 | |
FIRDynamicLinkResolverHandler | DynamicLinkResolverHandler |
FIRDynamicLinkUniversalLinkHandler | DynamicLinkUniversalLinkHandler |
FIRDynamicLinkShortenerCompletion | DynamicLinkShortenerCompletion |
枚举 | |
FIRDynamicLinkMatchConfidence | DynamicLinkMatchConfidence |
FIRDLRequiredMatchConfidence | DLRequiredMatchConfidence |
FIRDLRetrieveResult | DLRetrieveResult |
FIRShortDynamicLinkPathLength | ShortDynamicLinkPathLength |
实例 ID
之前 | 新 |
---|---|
函数 | |
FIRInstanceID.h | |
getWithHandler() |
getIDWithHandler() |
之前的用法:
FIRInstanceID.instanceID().get { identity, error in // Check identity and error } instanceID.instanceID().getID { identity, error in // Check identity and error } | |
deleteWithHandler() |
deleteIDWithHandler() |
之前的用法:
FIRInstanceID.instanceID().delete { error in // Check error } instanceID.instanceID().deleteID { error in // Check error } | |
类 | |
FIRInstanceID | InstanceID |
常量 | |
FIRInstanceIDScopeFirebaseMessaging | InstanceIDScopeFirebaseMessaging |
FIRInstanceIDTokenRefresh | InstanceIDTokenRefresh |
类型声明 | |
FIRInstanceIDTokenHandler | InstanceIDTokenHandler |
FIRInstanceIDDeleteTokenHandler | InstanceIDDeleteTokenHandler |
FIRInstanceIDHandler | InstanceIDHandler |
FIRInstanceIDDeleteHandler | InstanceIDDeleteHandler |
枚举 | |
FIRInstanceIDError | InstanceIDError |
FIRInstanceIDAPNSTokenType | InstanceIDAPNSTokenType |
邀请
之前 | 新 |
---|---|
类 | |
FIRInvites | Invites |
FIRInvitesTargetApplication | InvitesTargetApplication |
FIRReceivedInvite | ReceivedInvite |
常量 | |
FIRInvitesErrorDomain | InvitesErrorDomain |
枚举 | |
FIRInvitesErrorCode | InvitesErrorCode |
FIRReceivedInviteMatchType | ReceivedInviteMatchType |
协议 | |
FIRInviteBuilder | InviteBuilder |
FIRInviteDelegate | InviteDelegate |
消息传递
之前 | 新 |
---|---|
函数 | |
FIRMessaging | |
connect(completion:) | connect(handler:) |
类 | |
FIRMessagingMessageInfo | MessagingMessageInfo |
FIRMessagingRemoteMessage | MessagingRemoteMessage |
FIRMessaging | Messaging |
常量 | |
FIRMessagingSendSuccess | MessagingSendSuccess |
FIRMessagingSendError | MessagingSendError |
FIRMessagingMessagesDeleted | MessagingMessagesDeleted |
FIRMessagingConnectionStateChanged | MessagingConnectionStateChanged |
FIRMessagingRegistrationTokenRefreshed | MessagingRegistrationTokenRefreshed |
类型声明 | |
FIRMessagingFCMTokenFetchCompletion | MessagingFCMTokenFetchCompletion |
FIRMessagingDeleteFCMTokenCompletion | MessagingDeleteFCMTokenCompletion |
枚举 | |
FIRMessagingError | MessagingError |
FIRMessagingMessageStatus | MessagingMessageStatus |
FIRMessagingAPNSTokenType | MessagingAPNSTokenType |
协议 | |
FIRMessagingDelegate | MessagingDelegate |
Remote Config
之前 | 新 |
---|---|
函数 | |
FIRRemoteConfig | |
setDefaultsFromPlistFileName(_:) | setDefaults(fromPlist:) |
setDefaultsFromPlistFileName(_:namespace) | setDefaults(fromPlist:namespace) |
类 | |
FIRRemoteConfigValue | RemoteConfigValue |
FIRRemoteConfigSettings | RemoteConfigSettings |
FIRRemoteConfig | RemoteConfig |
常量 | |
FIRNamespaceGoogleMobilePlatform | NamespaceGoogleMobilePlatform |
FIRRemoteConfigThrottledEndTimeInSecondsKey | RemoteConfigThrottledEndTimeInSecondsKey |
FIRRemoteConfigErrorDomain | RemoteConfigErrorDomain |
类型声明 | |
FIRRemoteConfigFetchCompletion | RemoteConfigFetchCompletion |
枚举 | |
FIRRemoteConfigFetchStatus | RemoteConfigFetchStatus |
FIRRemoteConfigError | RemoteConfigError |
FIRRemoteConfigSource | RemoteConfigSource |
存储
之前 | 新 |
---|---|
函数 | |
FIRStorageReference | |
put(_:) | putData(_:) |
put(_:metadata:) | putData(_:metadata:) |
put(_:metadata:completion:) | putData(_:metadata:completion:) |
putFile(_:) | putFile(from:) |
putFile(_:metadata:) | putFile(from:metadata:) |
putFile(_:metadata:completion:) | putFile(from:metadata:completion:) |
data(withMaxSize:completion:) | getData(maxSize:completion:) |
metadata(completion:) | getMetadata(completion:) |
update(_:completion:) | updateMetadata(_:completion:) |
类 | |
FIRStorage | Storage |
FIRStorageDownloadTask | StorageDownloadTask |
FIRStorageMetadata | StorageMetadata |
FIRStorageObservableTask | StorageObservableTask |
FIRStorageReference | StorageReference |
FIRStorageTask | StorageTask |
FIRStorageTaskSnapshot | StorageTaskSnapshot |
FIRStorageUploadTask | StorageUploadTask |
常量 | |
FIRStorageErrorDomain | StorageErrorDomain |
枚举 | |
FIRStorageTaskStatus | StorageTaskStatus |
FIRStorageErrorCode | StorageErrorCode |
协议 | |
FIRStorageTaskManagement | StorageTaskManagement |
类型声明 | |
FIRStorageHandle | StorageHandle |
FIRStorageVoidDataError | StorageVoidDataError |
FIRStorageVoidError | StorageVoidError |
FIRStorageVoidMetadata | StorageVoidMetadata |
FIRStorageVoidMetadataError | StorageVoidMetadataError |
FIRStorageVoidSnapshot | StorageVoidSnapshot |
FIRStorageVoidURLError | StorageVoidURLError |