Different Launch URLs according to platform oneSignal push notifications

32 Views Asked by At

I'm trying to create a function that delivers a push notification to all app's users that redirect the user to the corresponding aplication's store accordind to the platform (one for iOS and another for Android). Here is my code:

    await OneSignal.shared.setAppId('APP-ID');
    await OneSignal.shared
        .promptUserForPushNotificationPermission()
        .then((accepted) {});
    OneSignal.shared.setNotificationOpenedHandler((openedResult) {
      OSNotificationDisplayType.notification;
    });
    OneSignal.shared.setNotificationWillShowInForegroundHandler((event) {
      OSNotificationDisplayType.notification;
    });
  } 


Future<void> addPosts(
    String cdMessage,
    String cdCpfCnpj,
  ) async {
    const url = "https://apps.apple.com/br/app/integra-on/id1620788591";
    await http.post(Uri.https('onesignal.com', '/api/v1/notifications'),
        body: jsonEncode({
          "app_id": "APP-ID",
          "include_external_user_ids": [cdCpfCnpj],
          "data": {"platform": "IOS","foo": "bar"},
          "platform": "IOS",
          "url": url,
          "contents": {"en": cdMessage}
        }),
        headers: {
          "Accept": "application/json",
          "content-type": "application/json",
          "Authorization":
              "Basic KEY"
        });
    // var data = response.body;
  }

i've tried to use 'Platform.isAndroid\Platform.isIOS', but it refers for the app sending the notifications, not the one recieving them. Anyone can help please?

0

There are 0 best solutions below