MCPcopy Create free account
hub / github.com/OneSignal/react-native-onesignal / load

Function load

examples/demo/src/hooks/useOneSignal.ts:221–291  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

219 };
220
221 const load = async () => {
222 const nextAppId = resolveAppId();
223 const [nextConsentRequired, nextPrivacyConsentGiven, nextIamPaused, nextLocationShared] =
224 await Promise.all([
225 preferences.getConsentRequired(),
226 preferences.getPrivacyConsent(),
227 preferences.getIamPaused(),
228 preferences.getLocationShared(),
229 ]);
230 const storedExternalUserId = (await preferences.getExternalUserId()) ?? undefined;
231
232 apiService.setAppId(nextAppId);
233
234 OneSignal.Debug.setLogLevel(LogLevel.Verbose);
235 OneSignal.setConsentRequired(nextConsentRequired);
236 OneSignal.setConsentGiven(nextPrivacyConsentGiven);
237 OneSignal.initialize(nextAppId);
238
239 OneSignal.LiveActivities.setupDefault({
240 enablePushToStart: true,
241 enablePushToUpdate: true,
242 });
243
244 OneSignal.InAppMessages.setPaused(nextIamPaused);
245 OneSignal.Location.setShared(nextLocationShared);
246
247 if (storedExternalUserId) {
248 OneSignal.login(storedExternalUserId);
249 }
250
251 OneSignal.InAppMessages.addEventListener('willDisplay', handleIamWillDisplay);
252 OneSignal.InAppMessages.addEventListener('didDisplay', handleIamDidDisplay);
253 OneSignal.InAppMessages.addEventListener('willDismiss', handleIamWillDismiss);
254 OneSignal.InAppMessages.addEventListener('didDismiss', handleIamDidDismiss);
255 OneSignal.InAppMessages.addEventListener('click', handleIamClick);
256 OneSignal.Notifications.addEventListener('click', handleNotificationClick);
257 OneSignal.Notifications.addEventListener('permissionChange', permissionHandler);
258 OneSignal.Notifications.addEventListener(
259 'foregroundWillDisplay',
260 handleForegroundWillDisplay,
261 );
262
263 OneSignal.User.pushSubscription.addEventListener('change', pushSubHandler);
264 OneSignal.User.addEventListener('change', userChangeHandler);
265
266 console.log(`OneSignal initialized with app ID: ${nextAppId}`);
267
268 const externalId = await OneSignal.User.getExternalId();
269 const [pushId, pushOptedIn, hasPerm] = await Promise.all([
270 OneSignal.User.pushSubscription.getIdAsync(),
271 OneSignal.User.pushSubscription.getOptedInAsync(),
272 OneSignal.Notifications.getPermissionAsync(),
273 ]);
274
275 setAppId(nextAppId);
276 setConsentRequiredState(nextConsentRequired);
277 setPrivacyConsentGivenState(nextPrivacyConsentGiven);
278 setInAppMessagesPaused(nextIamPaused);

Callers 1

useOneSignalStateFunction · 0.85

Calls 14

resolveAppIdFunction · 0.85
getConsentRequiredMethod · 0.80
getPrivacyConsentMethod · 0.80
getIamPausedMethod · 0.80
getLocationSharedMethod · 0.80
getExternalUserIdMethod · 0.80
setAppIdMethod · 0.80
setConsentRequiredMethod · 0.80
addEventListenerMethod · 0.80
setLogLevelMethod · 0.65
initializeMethod · 0.65
loginMethod · 0.65

Tested by

no test coverage detected