invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.53k stars 2.18k forks source link

FCM Token returns null on production in App Store, Both iOS and Android #3211

Closed Dellybro closed 4 years ago

Dellybro commented 4 years ago

Issue

Describe your issue here

When in Production environment AKA the app store, the FCM Token does not seem to be delivered to our application even when the user selects allow

import firebase                  from 'react-native-firebase';

functionalComponent() {
useEffect(() => {
        // The idea is once the user has logged in we will be able to check permissions
        //  Once we check permissions we will only upload tokens that aren't identical to the one
        //  The user already has within their DynamoDB Row
        if(cognitoUser.id) {
            checkPermissions();
        }
    }, [cognitoUser])

    async function checkPermissions() {
        const enabled = await firebase.messaging().hasPermission();
        if (enabled) {
            getToken();
        } else {
            requestPermission();
        }
    }

    async function getToken() {        
        try {
            let { token } = await registerTokenForUser(cognitoUser.fcmToken);

            // We only upload if the the FCM Token is different
            // Token return null so this function never runs.
            if (cognitoUser.fcmToken !== token) {
                await syncFCMToken(token);
            }
        }
        catch(error) {
            console.log(error);
        }
    }

    async function requestPermission() {
        try {
            await firebase.messaging().requestPermission();
            // User has authorised
            getToken();
        } catch (error) {
            // User has rejected permissions
        }
    }

// This function is used to grab the FCM Token and send it to sendbird then sends it back to the fn
export const registerTokenForUser = (token) => (
    new Promise(async (resolve, reject) => {
        const sb = SendBird.getInstance();

        try {
            if (Platform.OS === 'ios') {
                await getAPNSToken();
            }

            let FCMToken = await firebase.messaging().getToken();

            if (FCMToken !== token) {
                sb.registerGCMPushTokenForCurrentUser(FCMToken, function(result, err) {
                    if (err) return reject(err);

                    resolve({ result, token: FCMToken });
                });
            } else {
                resolve({ token: FCMToken });
            }
        } catch (err) {
            reject(err);
        }
    })
);
...

Project Files

Javascript

import firebase from 'react-native-firebase';

package.json:

"react-native-firebase": "^5.5.6",
# N/A

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

#### `ios/Podfile`: # Required by RNFirebase pod 'Firebase/Core', '~> 6.3.0' pod 'Firebase/Messaging', '~> 6.3.0' - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 10.15.3 CPU: (8) x64 Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz Memory: 114.07 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.4.1 - ~/.nvm/versions/node/v10.4.1/bin/node npm: 6.1.0 - ~/.nvm/versions/node/v10.4.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 IDEs: Android Studio: 3.5 AI-191.8026.42.35.5900203 Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.4 => 0.61.4 npmGlobalPackages: react-native-cli: 2.0.1 ``` - **Platform that you're experiencing the issue on**: - [ x] iOS - [x ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [x ] Both - **`react-native-firebase` version you're using that has this issue:** - `e.g. 5.4.3` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `Y/N` & `VERSION`


Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

tmaly1980 commented 4 years ago

Did you call registerForRemoteNotifications?

https://invertase.io/oss/react-native-firebase/v6/messaging/quick-start#registering-devices-with-fcm

devanshsadhotra25 commented 4 years ago

@Dellybro were u able to solve this?

JafetGtz commented 2 years ago

@Dellybro were u able to solve this?