Overview
The TikTok Clone app uses three core Firebase services:Firebase Storage
Stores video files uploaded by users
Cloud Firestore
NoSQL database for posts, users, and comments
Firebase Analytics
Tracks user engagement and app usage
Step 1: Create a Firebase Project
Go to Firebase Console
Navigate to Firebase Console and sign in with your Google account.
Step 2: Add iOS App to Firebase
Add app nickname (optional)
Enter a nickname like
TikTok Clone iOS to identify this app in the console.Download configuration file
- Click Download GoogleService-Info.plist
- Save the file - you’ll add it to Xcode next
- Click Next
Add GoogleService-Info.plist to Xcode
- Open your Xcode project
- Right-click the KD Tiktok-Clone folder
- Select Add Files to “KD Tiktok-Clone”…
- Choose the downloaded
GoogleService-Info.plist - Ensure “Copy items if needed” is checked
- Click Add
Step 3: Enable Cloud Firestore
Firestore stores all post metadata, user profiles, and comments.Choose Firestore location
Select a region close to your users (e.g.,
us-central or us-east1), then click Enable.The location cannot be changed after creation, so choose carefully.
Create Post collection
The app expects a
Post collection. Click Start collection:- Collection ID:
Post - Click Next
Add sample document
Add a test document with these fields:
Click Save
| Field | Type | Value |
|---|---|---|
video | string | sample.mp4 |
videoURL | string | https://firebase.storage.example.com/videos/sample.mp4 |
videoFileExtension | string | mp4 |
videoHeight | number | 1920 |
videoWidth | number | 1080 |
author | string | user123 |
autherName | string | John Doe |
caption | string | Check out my first video! |
music | string | Original Sound |
likeCount | number | 0 |
shareCount | number | 0 |
commentID | string | comment123 |
pageNumber | number | 1 |
The
pageNumber field is used for pagination in the home feed.Firestore Data Structure
The app uses this Firestore schema:How Posts Are Fetched
The app uses paginated queries to load videos:PostsRequest.swift:22-34
Videos are loaded in batches of 5-10 posts based on the
pageNumber field.Step 4: Enable Firebase Storage
Firebase Storage stores the actual video files.Video Upload Flow
Here’s how videos are uploaded to Firebase Storage:VideoPostRequest.swift:21-54
The upload process:
- Upload video to Storage
- Get the download URL
- Save post metadata + URL to Firestore
Step 5: Configure Firebase Analytics
Analytics is automatically enabled when you add Firebase to your app.Analytics data has a delay of up to 24 hours. Use DebugView for real-time testing.
Step 6: Update Security Rules (Production)
Before launching your app, update security rules:Firestore Rules
Storage Rules
Testing Your Firebase Setup
Check Firestore connection
The home feed should load posts from your Firestore database. Check Xcode console for logs:
Test video upload
- Tap the + button to record a video
- Grant camera and microphone permissions
- Record a short video
- Add a caption and tap Post
- Check Firebase Console → Storage to see the uploaded file
Troubleshooting
Error: Firebase app not initialized
Error: Firebase app not initialized
Solution: Verify that:
GoogleService-Info.plistis in your Xcode project- The file is included in the app target
FirebaseApp.configure()is called inAppDelegate
Error: Permission denied on Firestore
Error: Permission denied on Firestore
Solution: Check your Firestore security rules. For development, use test mode:
Videos not uploading to Storage
Videos not uploading to Storage
Solution:
- Verify Storage is enabled in Firebase Console
- Check Storage security rules allow writes
- Ensure video file size is under 50MB
- Check network connectivity
Bundle ID mismatch error
Bundle ID mismatch error
Solution: The Bundle ID in Xcode must match Firebase Console:
- Check Xcode: Target → Signing & Capabilities → Bundle Identifier
- Check Firebase: Project Settings → Your apps → iOS apps
- Update to match, then re-download
GoogleService-Info.plist
Firebase Console Overview
Key sections you’ll use:Firestore Database
View and edit posts, users, and comments
Storage
Browse uploaded videos and manage storage
Analytics
Track user engagement and app metrics
Project Settings
Manage API keys and app configurations
Next Steps
Architecture
Learn about MVVM, RxSwift, and the app’s code structure
API Reference
Explore Firebase request methods and data models
Best Practices
Development vs Production:
- Development: Use test mode for easier debugging
- Production: Implement authentication and strict security rules
Video Optimization:
- Keep videos under 30 seconds
- Use H.264 codec for best compatibility
- Compress videos to 720p or 1080p max
- Implement video transcoding for production apps