Office Space
Office Space

Reputation: 1

Huawei push kit integration with react-native project

I tried integrating Huawei push kit with my react-native app for ios.

But its not working.

If anybody have ever succeeded in doing so, then please share.

I tried every step provided here, as per the official documentationHms push kit for ios.

But still failed.

EDIT

signing and capabilities from Xcode

trying to get device token using below code snippet but HmsPushInstanceId itself is null.

import {
    HmsPushEvent,
    HmsPushInstanceId,
    HmsPushMessaging,
    // RNRemoteMessage,
} from '@hmscore/react-native-hms-push';
import { useEffect } from 'react';

import { isDeviceInChina } from '../../globalization/utils/getCountry';

function useHuwaeiPushService({ setUserAndToken = () => {} }) {

    const activateHuwaeiPush = () => {
        HmsPushMessaging?.turnOnPush()
            .then((result) => {
                console.log('turnOnPush', result);
            })
            .catch((err) => {
                console.log(`[turnOnPush] Error/Exception: ${JSON.stringify(err)}`);
            });
    };

    const getHuwaeiPushToken = async () => {
        console.log(
            'HmsPushInstanceId:: ',
            HmsPushInstanceId,
            HmsPushMessaging,
            HmsPushEvent,
        );
        if (!isDeviceInChina()) {
            return;
        }

        activateHuwaeiPush();

        HmsPushInstanceId?.getToken('')
            .then((result) => {
                console.log('getToken::', result);
                setUserAndToken((pv) => {
                    return {
                        ...pv,
                        messagingToken: result?.result,
                    };
                });
            })
            .catch((err) => {
                console.log(`[getToken] Error/Exception: ${JSON.stringify(err)}`);
            });
    };

    return {
        getHuwaeiPushToken,
    };
}

export default useHuwaeiPushService;

Upvotes: 0

Views: 147

Answers (0)

Related Questions