initPlatformState method

Future initPlatformState()

Implementation

Future initPlatformState() async {
  OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);

  OneSignal.shared.setRequiresUserPrivacyConsent(_requireConsent);

  OneSignal.shared
      .setNotificationOpenedHandler((OSNotificationOpenedResult result) {
    print('NOTIFICATION OPENED HANDLER CALLED WITH: $result');
  });

  OneSignal.shared.setNotificationWillShowInForegroundHandler(
          (OSNotificationReceivedEvent event) {
        print('FOREGROUND HANDLER CALLED WITH: $event');

        /// Display Notification, send null to not display
        event.complete(null);
      });

  OneSignal.shared
      .setInAppMessageClickedHandler((OSInAppMessageAction action) {

  });

  OneSignal.shared
      .setSubscriptionObserver((OSSubscriptionStateChanges changes) {
    print("SUBSCRIPTION STATE CHANGED: ${changes.jsonRepresentation()}");
  });

  OneSignal.shared.setPermissionObserver((OSPermissionStateChanges changes) {
    print("PERMISSION STATE CHANGED: ${changes.jsonRepresentation()}");
  });

  OneSignal.shared.setEmailSubscriptionObserver(
          (OSEmailSubscriptionStateChanges changes) {
        print("EMAIL SUBSCRIPTION STATE CHANGED ${changes
            .jsonRepresentation()}");
      });

  OneSignal.shared
      .setSMSSubscriptionObserver((OSSMSSubscriptionStateChanges changes) {
    print("SMS SUBSCRIPTION STATE CHANGED ${changes.jsonRepresentation()}");
  });

  OneSignal.shared.setOnWillDisplayInAppMessageHandler((message) {
    print("ON WILL DISPLAY IN APP MESSAGE ${message.messageId}");
  });

  OneSignal.shared.setOnDidDisplayInAppMessageHandler((message) {
    print("ON DID DISPLAY IN APP MESSAGE ${message.messageId}");
  });

  OneSignal.shared.setOnWillDismissInAppMessageHandler((message) {
    print("ON WILL DISMISS IN APP MESSAGE ${message.messageId}");
  });

  OneSignal.shared.setOnDidDismissInAppMessageHandler((message) {
    print("ON DID DISMISS IN APP MESSAGE ${message.messageId}");
  });

  // NOTE: Replace with your own app ID from https://www.onesignal.com
  await OneSignal.shared.setAppId(admodel?.oneSignalApp ?? '');

  // iOS-only method to open launch URLs in Safari when set to false
  OneSignal.shared.setLaunchURLsInApp(false);
  OneSignal.shared.consentGranted(true);

  bool requiresConsent = await OneSignal.shared.requiresUserPrivacyConsent();
  OneSignal.shared.promptUserForPushNotificationPermission().then((accepted) {
    print("Accepted permission: $accepted");
  });
  _enableConsentButton = requiresConsent;


  OneSignal.shared.disablePush(false);
  var canRequestAds = await ConsentManager.instance.canRequestAds();
  if (!canRequestAds) {
    return;
  }
}