react-native-test-firebase-sdk
v1.0.0
Published
Your Firebase SDK
Downloads
12
Readme
Your Firebase SDK
A React Native SDK that allows developers to generate FCM (Firebase Cloud Messaging) tokens using a pre-configured Firebase instance, eliminating the need to set up their own Firebase project. Supports both Android and iOS.
Features
Initialize Firebase with pre-configured credentials.
Generate FCM tokens for push notifications.
Debug mode for detailed logging.
TypeScript support for type safety.
Prerequisites
React Native >= 0.60.0
Node.js >= 14.x
@react-native-firebase/app and @react-native-firebase/messaging libraries
Android: Internet permission in AndroidManifest.xml
iOS: Push Notifications capability enabled in Xcode
Installation
Install the SDK and dependencies:
npm install your-firebase-sdk @react-native-firebase/app @react-native-firebase/messaging
Android Setup:
Add the following permission to android/app/src/main/AndroidManifest.xml:
No google-services.json is required, as the SDK handles Firebase configuration.
iOS Setup:
Update your Podfile to include Firebase dependencies:
pod 'Firebase', '~> 10.0' pod 'Firebase/Messaging'
Run pod install in the ios directory.
Enable Push Notifications in Xcode under Capabilities.
No GoogleService-Info.plist is required.
Usage
Initialize the SDK: Import and initialize the SDK with your provided Firebase credentials.
import FirebaseSDK from 'your-firebase-sdk';
const sdk = new FirebaseSDK({ apiKey: 'YOUR_FIREBASE_API_KEY', projectId: 'YOUR_FIREBASE_PROJECT_ID', messagingSenderId: 'YOUR_MESSAGING_SENDER_ID', appId: 'YOUR_FIREBASE_APP_ID', debugMode: true, });
Generate FCM Token: Call the initialize method to set up Firebase, then use generateFCMToken to get the FCM token.
import React, { useEffect } from 'react'; import { View, Text } from 'react-native'; import FirebaseSDK from 'your-firebase-sdk';
const sdk = new FirebaseSDK({ apiKey: 'YOUR_FIREBASE_API_KEY', projectId: 'YOUR_FIREBASE_PROJECT_ID', messagingSenderId: 'YOUR_MESSAGING_SENDER_ID', appId: 'YOUR_FIREBASE_APP_ID', debugMode: true, });
const App = () => { useEffect(() => { const initSDK = async () => { try { await sdk.initialize(); const fcmToken = await sdk.generateFCMToken(); console.log('Generated FCM Token:', fcmToken); } catch (error) { console.error('SDK Error:', error.message); } }; initSDK(); }, []);
return ( <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> Firebase SDK Demo ); };
export default App;
API Reference
new FirebaseSDK(config: SDKConfig)
Creates an instance of the SDK.
config.apiKey: Firebase API key.
config.projectId: Firebase project ID.
config.messagingSenderId: Firebase messaging sender ID.
config.appId: Firebase app ID.
config.debugMode (optional): Enable debug logging (default: false).
initialize(): Promise
Initializes Firebase with the provided configuration.
generateFCMToken(): Promise
Generates an FCM token for the device. Requires initialize to be called first.
getConfig(): SDKConfig
Returns the current SDK configuration.
Debugging
Set debugMode: true in the SDK config to enable detailed console logs for initialization and token generation.
Support
For issues or feature requests, please contact [[email protected]] or open an issue on the GitHub repository.
