OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

[question]: How to disable ios PlatformException

Open Remas-Safi opened this issue 2 years ago • 2 comments
trafficstars

How can we help?

I am using different methods of Onesignal, where I may for sure get errors, for example, sendTags will throw an error if the account is not upgraded, whereas for my app I have the account upgraded for the production environment but not the dev, so I need to disable logging for dev.

For this and different kinds of errors I am handling it using try.. catch something like this:

         try {
          await oneSignalShared.sendTags({
            "name": user.fullName,
            "id": user.id.toString(),
          }).catchError((e) {
            log(e.toString());
            return {'': ''};
          });
        } catch (_) {}

However, OneSignal is still throwing PlatformException for this, How can I disable this?

FYI, Not sure if this helps, but I've set the logs level to

  oneSignalShared
        .setLogLevel(OSLogLevel.none, OSLogLevel.none)

Also the method setAppId says The initializer for OneSignal. Note that this initializer accepts an iOSSettings object, in Android you can pass null. but it only accepts the app id, and so far I can't find a way to disable this PlatformException, any hint will be a great help

Remas-Safi avatar Jul 03 '23 12:07 Remas-Safi

Hi @Remas-Safi,

Thanks for reaching out. It looks like there are a few things you are asking about.

  1. For this question:

However, OneSignal is still throwing PlatformException for this, How can I disable this?

Can you share the exception you are getting? For example:

Error: PlatformException(OneSignal, Encountered an error updating tags (400): {"errors":["App is limited to a maximum of 20 tags on a given player"],"success":false}, null, null)
  1. I recommend during testing and debugging, you set oneSignalShared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none). You will see more logs to figure out any errors. Then you can set it back to OSLogLevel.none for production.

  2. I am sorry that this comment of The initializer for OneSignal. Note that this initializer accepts an iOSSettings object, in Android you can pass null is outdated and incorrect. You should only pass a string app ID. Is this method giving you an error?

nan-li avatar Jul 05 '23 23:07 nan-li

@nan-li First thank you for your response.

My exact problem is the following:

PlatformException(OneSignal, Encountered an error when setLanguage: Unable to set Language: the current user is not registered with OneSignal, null, null)

Where ever I am calling setLanguage I catch any thrown error..... Also, I am trying to solve this issue by making sure this is called after setAppId and after setLogLevel. So my idea is even if this error occurred I don't want it to be thrown as PlatformException cause I am using Sentry and it always catching it... so I don't want it to be reported for Sentry.

This is exactly my issue, I will be thankful if you can provide a way to fix this issue, or Am I doing something wrong?

For iOSSettings, it was actually one of the ways I found as a suggestion to disable the PlatformException I am getting. so not really I am not getting any errors with setAppId

Remas-Safi avatar Jul 06 '23 06:07 Remas-Safi