pusher / push-notifications-flutter

Official Pusher Beams Flutter client plugin (iOS, Android and Web), receive notifications easily on your Flutter application with Pusher Beams.
https://pub.dev/packages/pusher_beams
MIT License
10 stars 21 forks source link

[QUESTION] IOS start method #48

Open jehhxuxu opened 5 months ago

jehhxuxu commented 5 months ago

Hello, first, thank you for the awesome package. I have a question about the start method on IOS, does the start method ask for notification permission? on Android, it doesn't. Can I change that? I have an onboarding notification screen to ask permission, but it's not working on IOS because it was previously asked.

benw-pusher commented 5 months ago

The library will ask for permission if permission is not currently granted. If you call start and permissions are already granted then there is no requirement to show a pop up so the library continues without this.

jehhxuxu commented 5 months ago

But I just want to ask for permission on my onboarding screen, and not when the user opens the app, can I change this behavior? What do you suggest in that situation?

The IOS docs of Push Beamer said: "We recommend start is always called in the application didFinishLaunchingWithOptions callback. Note that you can still control when you show the request for push notification prompt, start does not call this prompt."

benw-pusher commented 5 months ago

You have raised this issue against the Flutter lib - are you using the Flutter library or directly using the Swift library?

jehhxuxu commented 5 months ago

I'm using the Flutter package, I just saw the native to check if the Flutter package is doing the same as the native... and apparently, it's not... but do you have some options here? if I do not want to check permission when the user opens the app, how can I achieve that?

shanaka-sync commented 5 months ago

flutter_local_notifications will do the job.

  Future<void> initNotifications() async {
    FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

    AndroidFlutterLocalNotificationsPlugin aflnp = flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>();
    if(aflnp != null){
      await aflnp.requestNotificationsPermission();
    }
  }
jehhxuxu commented 5 months ago

@shanaka-sync don't understand your idea... 🤔

shanaka-sync commented 5 months ago
> @shanaka-sync don't understand your idea... 🤔

So do you want to ask permission by code. this is how it do.
You can get it by calling flutterLocalNotificationsPlugin.initialize method.
This is how it do.

```

const AndroidNotificationChannel channel = AndroidNotificationChannel( 'channel_id', 'Notification Channel', description: 'Channel Description', importance: Importance.max, );

const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('ic_stat_name');

// Check out the constructor parameters.
final DarwinInitializationSettings initializationSettingsDarwin = DarwinInitializationSettings();

final InitializationSettings initializationSettings = InitializationSettings(
  android: initializationSettingsAndroid,
  iOS: initializationSettingsDarwin,
);

await flutterLocalNotificationsPlugin.initialize(
  initializationSettings,
  onDidReceiveNotificationResponse: (NotificationResponse notification) async {
    if(kDebugMode){
      print("Clicked Notification: $notification");
    }
  }
);

AndroidFlutterLocalNotificationsPlugin aflnp = flutterLocalNotificationsPlugin
    .resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>();
if(aflnp != null){
  await aflnp.createNotificationChannel(channel);

  await aflnp.requestNotificationsPermission();
}

Check how they do that in [flutter_local_notification](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/lib/main.dart)
jehhxuxu commented 4 months ago

Yes, thank you, I know how to ask for permission, but this package asks when the user opens the app and I don't want to. I just want to change this behavior, I want to choose when to ask for permission... this is the issue about it =/

benw-pusher commented 4 months ago

I don't believe it is possible to control when the prompt is shown on iOS. I will raise this internally for review - the behaviour does appear to differ between Android and iOS.