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

[question]: Please can someone help I can't find anything in the documentation to get this code working #639

Closed
CameronGoosen opened this issue Sep 18, 2023 · 4 comments

Comments

@CameronGoosen
Copy link

CameronGoosen commented Sep 18, 2023

Using Unity 2022.3.9f1

I've upgraded to version 5.0.2 from 3.0.x

using OneSignalSDK;

    OneSignal.NotificationOpened += HandleNotificationOpened;
    OneSignal.NotificationWillShow += HandleNotificationReceived;

    private Notification HandleNotificationReceived(Notification notification)
    {
        //return
    }

    private void HandleNotificationOpened(NotificationOpenedResult result)
    {

    }

OneSignal.NotificationOpened: 'OneSignal does not contain a definition for NotificationOpened'
OneSignal.NotificationWillShow: 'OneSignal does not contain a definition for NotificationWillShow '
Notification: 'The type or namespace name Notification could not be found'
NotificationOpenedResult : 'The type or namespace name NotificationOpenedResult could not be found'

Losing my mind with this upgrade.

@CameronGoosen
Copy link
Author

I have already tried:

Troubleshooting

If you run into the following errors :

Assets/OneSignal/Example/OneSignalExampleBehaviou.cs: error CS0246: The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)

Assets/OneSignal/Attribution/OneSignalVSAttribution.cs: error CS0117: 'OneSignal' does not contain a definition for '...'

  1. Delete the directory at Assets/OneSignal and the xml file at Assets/Plugins/Android/OneSignalConfig.plugin/AndroidManifest.xml

  2. Check the menu at Window > OneSignal SDK Setup to see if there are any remaining steps to run

If you would like to regenerate the OneSignal assets, remove the OneSignal Unity SDK packages (Android, Core, iOS) from your project and import the OneSignal SDK again.

@AFB-MORA
Copy link

Checkout Migration Guide


5.0.2 version of your code is:

        public virtual void Initialize() {
            OneSignal.Initialize(appId);

            OneSignal.Notifications.Clicked += HandleNotificationClicked;
            OneSignal.Notifications.ForegroundWillDisplay += HandleNotificationWillShow;
        }

        protected virtual void HandleNotificationClicked(object sender, NotificationClickEventArgs notification) {
             // Handle opened notification
        }

        protected virtual void HandleNotificationWillShow(object sender, NotificationWillDisplayEventArgs notification) {
            notification.PreventDefault();
        }

@shepherd-l
Copy link
Contributor

We have a list of 5.x methods in our migration guide and in our docs:

You can also see our example app code here

As AFB-MORA suggested,

OneSignal.NotificationOpened should be OneSignal.Notifications.Clicked
OneSignal.NotificationWillShow should be OneSignal.Notifications.ForegroundWillDisplay

We have changed events to use EventHandlers - your code should look something like this

private void HandleNotificationClicked(object sender, NotificationClickEventArgs e) {
     // You can access the notification and result with
     e.Notification;
     e.Result;
}
private void HandleNotificationWillShow(object sender, NotificationWillDisplayEventArgs e) {
     // You can access the notification and choose to display it
     e.Notification;

     // You can also prevent OneSignal from displaying the notification immediately on return with e.PreventDefault()
     // This way you can edit the notification before it displays

     // Display the notification with
     e.Notification.Display();
}

Let me know if you have any issues

We are currently working on documentation to make upgrading clearer that has a list of method changes/renames from 3.x to 5.x

@shepherd-l
Copy link
Contributor

Going to close this issue for now, let me know if you have any further questions

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

3 participants