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

Can't init

Open yostrokon opened this issue 8 years ago • 13 comments

Can't init OneSignal

OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.verbose); await OneSignal.shared.init(---myapid----);

in response have V/OneSignal( 7769): Initializing the OneSignal Flutter SDK (0.1.0)

and that is ... next code after init line is not executed

dependancies: onesignal: ^1.0.0

yostrokon avatar Aug 20 '18 12:08 yostrokon

@yostrokon Can you try removing the await and tell me if push notifications work at all?

Also, does this occur in iOS or Android, or both?

Lastly, can you try explicitly using 1.0.1?

Nightsd01 avatar Aug 20 '18 18:08 Nightsd01

Sigh. This is also happening to me on iOS also, I'm using 1.0.1. I have removed the await also.

FaisalAbid avatar Aug 21 '18 02:08 FaisalAbid

@Nightsd01 print('starting'); OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.verbose); OneSignal.shared.init(---------); print('inited'); await OneSignal.shared.promptUserForPushNotificationPermission(fallbackToSettings: true); print('asked');

response is

I/flutter ( 5132): starting I/flutter ( 5132): inited E/flutter ( 5132): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception: E/flutter ( 5132): NoSuchMethodError: The getter 'keys' was called on null. E/flutter ( 5132): Receiver: null E/flutter ( 5132): Tried calling: keys E/flutter ( 5132): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5) E/flutter ( 5132): #1 OneSignal._processSettings (package:onesignal/onesignal.dart:302:40) E/flutter ( 5132): #2 OneSignal.init (package:onesignal/onesignal.dart:54:25) E/flutter ( 5132): . . . E/flutter ( 5132): #16 _drawFrame (dart:ui/hooks.dart:109:3) E/onesignal( 5132): promptPermission() is not applicable in Android. V/OneSignal( 5132): Initializing the OneSignal Flutter SDK (0.1.0)

Same with 1.0.1. No idea about iOS.

yostrokon avatar Aug 21 '18 04:08 yostrokon

Something similar was happening to me, in my case I got it working once I supplied iOS settings as args to the init call.

I believe this line is the problem: https://github.com/OneSignal/OneSignal-Flutter-SDK/blob/d33b258f2e911286eb72c666343d3c4deadc7345/lib/onesignal.dart#L302

If a settings map is not supplied to init, it would be null here.

rafacorrea avatar Aug 21 '18 08:08 rafacorrea

Very strange onesignal init was as in the method called from the future builder in the application widget. moved to the initState as shown in the example and seems something works.

yostrokon avatar Aug 21 '18 08:08 yostrokon

Hey @yostrokon - can you clarify what you mean?

FaisalAbid avatar Aug 21 '18 14:08 FaisalAbid

@FaisalAbid I have complex authorization with the couple of the external services and all of them are collected in one method returning future that was called as future in the FutureBuilder. So was tried to do onesignal.init in the same method. But nothing happened as is this issue. Today installed example application from the onesignal package and it worked. Tried to move onesignal.init to the initState method as is implemented in the example and things are started.

yostrokon avatar Aug 21 '18 15:08 yostrokon

I had to supply the iOSSettings. If you don't, an exception is thrown when the plugin tries to loop through its keys since it's null.

The docs and code is a bit misleading because it says you can you can pass null in Android and iOSSettings is a named argument that you can ignore.

daniel-van-niekerk avatar Aug 23 '18 13:08 daniel-van-niekerk

Thanks, I'll check that

FaisalAbid avatar Aug 24 '18 16:08 FaisalAbid

Still having the same issue.

E/onesignal(14453): promptPermission() is not applicable in Android.

Initialising like

    OneSignal.shared.init(oneSignalAppId, iOSSettings: {
      OSiOSSettings.autoPrompt: false,
      OSiOSSettings.inAppLaunchUrl: true
    });

lifenautjoe avatar Mar 05 '19 18:03 lifenautjoe

@lifenautjoe did you solve this problem ?

fahjan avatar Jul 15 '19 04:07 fahjan

use this instead OneSignal.shared.setAppId("YOUR_ONESIGNAL_APP_ID");

Divinoart avatar Jun 13 '21 00:06 Divinoart

use this instead OneSignal.shared.setAppId("YOUR_ONESIGNAL_APP_ID");

This is not setting One Signal. getDeviceState is returning null values.

elhe26 avatar Jan 25 '22 17:01 elhe26