TypeError: Cannot read property 'init' of null means the native Pushwoosh module is not available in the running app: the JavaScript layer loaded, but there is no native module behind it. In an Expo project this usually means the app is running without the native code, for example in Expo Go, or the native projects were not regenerated and rebuilt after installing the plugins.
1. Install both packages
expo install pushwoosh-expo-plugin
npm install pushwoosh-react-native-plugin --save
2. Register the config plugin in app.json / app.config.js, at the front of the plugins array:
{
"expo": {
"plugins": [
["pushwoosh-expo-plugin", {
"mode": "development",
"ios": { "PW_API_TOKEN": "__YOUR_DEVICE_API_TOKEN__" },
"android": { "apiToken": "__YOUR_DEVICE_API_TOKEN__" }
}]
]
}
}
Also set android.package, android.googleServicesFile (path to your google-services.json) and ios.bundleIdentifier.
3. Regenerate the native projects
npx expo prebuild
4. Run a development build, because Expo Go cannot load custom native modules. Build the app itself:
npx expo run:ios
npx expo run:android
Then check that initialisation happens in the root component of your app:
import Pushwoosh from 'pushwoosh-react-native-plugin';
Pushwoosh.init({ "pw_appid": "__YOUR_APP_ID__" });
Pushwoosh.register();
See the Expo integration guide for the full walkthrough.
Comments
0 comments
Please sign in to leave a comment.