ios icon indicating copy to clipboard operation
ios copied to clipboard

TypeError: undefined is not a function (near '..._pushNotificationIos.default.localNotification...')

Open DeveloperLocalizer opened this issue 3 years ago • 1 comments

I get the following error.

TypeError: undefined is not a function (near '..._pushNotificationIos.default.localNotification...')

I code a minimal example to send local push notifications when the app dont run at the foreground.

This is the code in my App.js

I add the library like descripted in the README.md.

Has anyone had this error before or knows what this could be? I have expanded the respective AppDelegates, and executed a "pod install". The React native version is 0.66.4

` import React, {useRef, useState, useEffect} from "react"; import {StyleSheet, Text, View, AppState} from "react-native"; import PushNotificationIOS from '@react-native-community/push-notification-ios';

const App = () => { const appState = useRef(AppState.currentState); const [appStateVisible, setAppStateVisible] = useState(appState.current);

useEffect(() => {
    console.log("called useEffect");
    AppState.addEventListener("change", _handleAppStateChange)

    return () => {
        AppState.removeEventListener("change", _handleAppStateChange)
    }
}, []);

const _handleAppStateChange = (nextAppState) => {
    if (appState.current.match(/inactive|background/) &&
        nextAppState === "active") {
        console.log("App has come to the foreground");
    } else {
        PushNotificationIOS.localNotification({
            title: 'Cold Weather Alert',
            message: `It's 3 degrees outside.`,
            playSound: true,
            soundName: 'default',
        });
    }

    appState.current = nextAppState;
    setAppStateVisible(appState.current);

    console.log("AppState: " , appState.current);
}

return (
    <View style={styles.container}>
        <Text style={styles.textStyle}>
            Current state is:
        </Text>
    </View>
);

};

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center", }, textStyle: { textAlign: "center", fontSize: 30, color: "black" } });

export default App;

`

DeveloperLocalizer avatar Apr 17 '22 18:04 DeveloperLocalizer

It is deprecated you can use other methods mentioned in the the documentation

Hamidkhanswb avatar May 19 '22 06:05 Hamidkhanswb

please use addNotificationRequest for that purpose 😄

Naturalclar avatar Oct 09 '22 16:10 Naturalclar