When creating an app, we often use the login function. There are methods for logging in using your Apple ID and logging in using Twitter and Facebook.
This time, we will simplify their implementation and manage accounts after login. I will describe the procedure to link Firebase and the application that can be done.
The actual login implementation is introduced in a separate article. -Implement Twitter login function using Firebase UI
environment ・ Swift version 5.3 ・ XCode version 12.3 CocoaPods version 1.10.1
Qiita seems to have a fixed amount of images that can be posted in a month, so I would like to make the image as minimal as possible. I'm sorry···.
Create an app that implements the login function. This time, I created it with the project name ** SampleAppleLogin **.
Make a copy of the ** Bundle Identifier ** in the image.
Create a new project in Firebase.
After accessing the Firebase console, click + Add Project
-> Specify the project name and click "Continue"
-> Enable Google Analytics for this project
disableto create a project ->
You have created a project. Click "Continue" when `is displayed
Click the iOS button from Project Overview
to add the app.
① Since there is a field to enter iOS bundle ID
in the application registration,
Copy and paste the Bundle Identifier of the app you just created here.
Other inputs are optional, so click Next.
Click GoogleService-Info.plist
to download and click Next
Subsequent items will be set later, so Go to "Next"-> "Next"-> "Proceed to Console".
Now that you have registered the app on Firebase, Perform the process to link with Firebase on the application side.
Click the magnifying glass mark at the top right of the screen. (Or command + spacebar) A search field will appear. Enter "Terminal" and press Enter.
First, move the directory.
I move the directory with the cd command. Enter the PATH of the app you created earlier as the destination. In my case, the command is as follows.
If you are not sure, drag and drop the created app folder.
$ cd Desktop/project/SampleAppleLogin
Next, create a Podfile.
$ pod init
Make sure the podfile is created just in case. In my case, the Podfile was created and it was in the following state.
$ ls
Podfile SampleAppleLogin SampleAppleLogin.xcodeproj
Edit the podfile.
$ vi Podfile
Add the installation target. There are two things to add.
pod 'FirebaseUI'
pod 'Firebase'
You need to be in edit mode first, so press i
.
Then you will see --INSERT --
on the bottom left.
In that state, you can enter characters.
I think that it will be as follows if I add it. (The contents are slightly different depending on the version.)
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'SampleAppleLogin' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for SampleAppleLogin
pod 'FirebaseUI' //add to
pod 'Firebase' //add to
end
Since it is necessary to save the file after adding,
Press esc
to cancel edit mode, then press: wq
in order to save.
Then install it.
$ pod install
If no error occurs, it's OK!
If it occurs, please try google with the error content. (Basically, there should be no error.)
I close Xcode once and open the app from Finder.
At this time, open the file with project name.xcworkspace
.
Next, I downloaded it when I created the project in Firebase,
Place the GoogleService-Info.plist
in your app.
Place it in the same hierarchy as ViewController.swift etc.
If you click GoogleService-Info.plist
, the screen in the middle will change.
Copy the value in the value column of the row REVERSED_CLIENT_ID
in it.
I think the content is com.googleuser ~
.
If you click the project name on the top level, the screen in the middle will change.
Select Info from the tags.
Open the URl Types
at the bottom and press+
to add.
Paste the one you just copied into the URL Schemes in the upper right.
Then open AppDelegate.swift and edit it as below.
AppDelegate.swift
import Firebase //add to
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure() //add to
return true
}
This article was planned to implement the login function in Firebase UI, so I have installed the Firebase UI with CocoaPods.
If you log in the other way, you may not need to install it, so Follow that method.
Also, so far, only cooperation has been completed, so You need to implement the actual login function.
The article about that is below. -Implement Twitter login function using Firebase UI
Thank you for watching until the end.
Recommended Posts