Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: RNOneSignal.initialize is not a function (it is undefined) #1767

Open
2 of 3 tasks
alimoli opened this issue Nov 27, 2024 · 1 comment
Open
2 of 3 tasks

[Bug]: RNOneSignal.initialize is not a function (it is undefined) #1767

alimoli opened this issue Nov 27, 2024 · 1 comment

Comments

@alimoli
Copy link

alimoli commented Nov 27, 2024

What happened?

TypeError: RNOneSignal.initialize is not a function (it is undefined)

Podfile

target 'OneSignalNotificationServiceExtension' do
	# Pods for OneSignalNotificationServiceExtension
	pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
end

NotificationService.swift

import UserNotifications

import OneSignalExtension

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var receivedRequest: UNNotificationRequest!
    var bestAttemptContent: UNMutableNotificationContent?
    // etc. as shown in the documentation here https://documentation.onesignal.com/docs/react-native-sdk-setup

PushNotificationProvider.tsx

        // Remove this method to stop OneSignal Debugging
	OneSignal.Debug.setLogLevel(LogLevel.Verbose);

	// OneSignal Initialization
	OneSignal.initialize(OneSignalAppId);

	// requestPermission will show the native iOS or Android notification permission prompt.
	// We recommend removing the following code and instead using an In-App Message to prompt for notification permission
	OneSignal.Notifications.requestPermission(true).catch((e) => {
		Log(LDebug, 'OneSignal requestPermission', e)
	})

Simulator Screenshot - iPhone SE (3rd generation) - 2024-11-27 at 18 27 32

Steps to reproduce?

1. Install pod (no problem)
2. Run the application for iOS via Metro
3. Get this error

What did you expect to happen?

Just to build correctly as presented in the documentation.

React Native OneSignal SDK version

Release 5.2.7

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

TypeError: RNOneSignal.initialize is not a function (it is undefined)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jennantilla
Copy link
Contributor

Hello there, thank you for your patience. Are you still having this issue? If so, can you provide some more details on your setup? Are you adding OneSignal to your app for the first time? Where are you calling the initialize method in the larger scheme of your app's code? It should be called during startup of the application.

You can also try removing the plugin and adding it again.

Thanks for the additional information!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants