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] IOS start method #48

Open
jehhxuxu opened this issue Jan 9, 2024 · 9 comments
Open

[QUESTION] IOS start method #48

jehhxuxu opened this issue Jan 9, 2024 · 9 comments

Comments

@jehhxuxu
Copy link

jehhxuxu commented Jan 9, 2024

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
Copy link

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
Copy link
Author

jehhxuxu commented Jan 10, 2024

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
Copy link

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

@jehhxuxu
Copy link
Author

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
Copy link

shanaka-sync commented Jan 29, 2024

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
Copy link
Author

jehhxuxu commented Feb 6, 2024

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

@shanaka-sync
Copy link

shanaka-sync commented Feb 7, 2024

> @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
Copy link
Author

jehhxuxu commented Feb 8, 2024

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
Copy link

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.

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