【发布时间】:2021-07-22 13:29:57
【问题描述】:
如何在 Flutter 应用中获取用户的 playerId?玩家 ID 可以在 One signal 网站中找到,但我希望在颤振应用程序中找到它并希望将其存储以将通知发送给特定用户。
【问题讨论】:
标签: flutter push-notification onesignal
如何在 Flutter 应用中获取用户的 playerId?玩家 ID 可以在 One signal 网站中找到,但我希望在颤振应用程序中找到它并希望将其存储以将通知发送给特定用户。
【问题讨论】:
标签: flutter push-notification onesignal
这是我启动onesignal的goto函数
Future<void> initOneSignal(BuildContext context) async {
/// Set App Id.
await OneSignal.shared.setAppId(SahityaOneSignalCollection.appID);
/// Get the Onesignal userId and update that into the firebase.
/// So, that it can be used to send Notifications to users later.̥
final status = await OneSignal.shared.getDeviceState();
final String? osUserID = status?.userId;
// We will update this once he logged in and goes to dashboard.
////updateUserProfile(osUserID);
// Store it into shared prefs, So that later we can use it.
Preferences.setOnesignalUserId(osUserID);
// The promptForPushNotificationsWithUserResponse function will show the iOS push notification prompt. We recommend removing the following code and instead using an In-App Message to prompt for notification permission
await OneSignal.shared.promptUserForPushNotificationPermission(
fallbackToSettings: true,
);
/// Calls when foreground notification arrives.
OneSignal.shared.setNotificationWillShowInForegroundHandler(
handleForegroundNotifications,
);
/// Calls when the notification opens the app.
OneSignal.shared.setNotificationOpenedHandler(handleBackgroundNotification);
}
【讨论】: