Description:
Calling promptUserForPushNotificationPermission on iOS displays a dialog if necessary but doesn't return a value afterwards on both the emulator and iPhone 6+, inference being that the Future never completes
Environment
Onesignal v1.05, installed via packages get and pubspec.yaml
[✓] Flutter (Channel dev, v1.2.2, on Mac OS X 10.13.6 17G5019, locale en-GB)
• Flutter version 1.2.2 at /Users/nicford/development/flutter
• Framework revision 007a415c2a (4 days ago), 2019-02-21 20:22:47 -0800
• Engine revision f1f19bba8f
• Dart version 2.2.0 (build 2.2.0-dev.2.1 c92d5ca288)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/nicford/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /Users/nicford/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.1, Build version 10B61
• ios-deploy 1.9.4
• CocoaPods version 1.5.3
[✓] Android Studio (version 3.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 32.0.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
[✓] VS Code (version 1.25.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 2.21.1
[✓] Connected device (1 available)
• iPhone 8 Plus • 11540FF4-FB7F-4BE2-A2AA-096C3DC48944 • ios • iOS 12.1 (simulator)
• No issues found!
Steps to Reproduce Issue:
packages getmain.dart code with the code belowNew code
import 'package:flutter/material.dart';
import 'package:onesignal/onesignal.dart';
void main() async {
await OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);
await OneSignal.shared.init(
'<APP ID>',
iOSSettings: {
OSiOSSettings.autoPrompt: false,
OSiOSSettings.inAppLaunchUrl: true
}
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
print('Before');
await OneSignal.shared.promptUserForPushNotificationPermission();
print('After');
},
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Now seeing similar behaviour with OneSignal.shared.setInFocusDisplayType
Hello,
Thank you for reporting this. It sounds like this might be a problem with several of the Flutter SDK methods. We will look into this. Thanks again
as @rgomezp said the problem might be with several methods. Another one is
await OneSignal.shared.setSubscription(true);
it got OneSignal working but it requires a bit more code to handle the whole logic
@rgomezp could you provide any updates when we may expect a new release?
for those who want to await for broken methods you can try that, I am not sure if this is the best way but it works
Future setSubscriptionObserverWrapper() async {
Completer c = Completer();
OneSignal.shared.setSubscriptionObserver((OSSubscriptionStateChanges changes) {
if (changes.to.userId != null) {
c.complete(changes);
}
});
return c.future;
}
@rgomezp do you know when we may expect any changes related to the above bugs? is it within a week, a month or more?
@mikechoch ,
Is hard at work trying to get a new version out. Thanks for your patience
@rgomezp any update?
Howdy,
I'm curious as to whether folks are calling the setRequiresUserPrivacyConsent method but never actually granting consent using the consentGranted method. If you are doing the first without the second, the SDK will never fully initialize and the methods will not do anything.
https://documentation.onesignal.com/docs/flutter-sdk#section--setrequiresuserprivacyconsent-
https://documentation.onesignal.com/docs/flutter-sdk#section--consentgranted-
Howdy,
I'm curious as to whether folks are calling thesetRequiresUserPrivacyConsentmethod but never actually granting consent using theconsentGrantedmethod. If you are doing the first without the second, the SDK will never fully initialize and the methods will not do anything.https://documentation.onesignal.com/docs/flutter-sdk#section--setrequiresuserprivacyconsent-
https://documentation.onesignal.com/docs/flutter-sdk#section--consentgranted-
I am noticing this issue as well. No, I do not call setRequiresUserPrivacyConsent at all in my code. Is this fix still in the works?.
I should clarify, this was fixed on the Android side but not iOS. Thanks for your patience while we work to resolve
I can fix this issue this weekend if no one gets to it before me :)
@Nightsd01 thanks Brad!
We're also facing this issue, hopefully the solution will be out soon!
Expect a release (most likely 2.1.0) that fixes these issues and adds In-App Messaging to iOS within the next week. Really sorry for the delay and I thank you for the patience. In the mean time, I would love to know any other methods causing hanging awaits.
Currently I see several methods (on iOS bridge) that will have hanging awaits, I will list them here as I fix them:
promptUserForPushNotificationPermission
setSubscription
setInFocusDisplayType
setExternalUserId
removeExternalUserId
setLocationShared
oneSignalLog
Also finding a few methods on Android with some hanging awaits:
setSubscription
oneSignalLog
promptPermission (Stubbed for Android, no prompt for push notification permission)
setLocationShared
@mikechoch please read my comment above about "setSubscription"