Skip to content

Not receiving push notifications when running Flutter app on iOS #78

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

Closed
CamronLDNF opened this issue Nov 14, 2021 · 3 comments
Closed
Assignees

Comments

@CamronLDNF
Copy link

CamronLDNF commented Nov 14, 2021

I'm using clevertap_plugin: 1.3.0.

I have followed your Flutter sdk documentation and read through the Push Notifications sections of your Android sdk and iOS sdk documentation as well. When I send notifications, they arrive on Android but not on iOS. How do I resolve this?

I saw this earlier issue that seems to be related. It says to send our APNS token first, but how do we do that? Unfortunately we don't have iOS experience, so it's a bit murky on how to implement that.

Your iOS sdk documentation on Push Notifications states "If you automatically integrated the SDK in the quick start guide, you have already enabled push notification support." Obviously that is not the case.

Please note: we already have FCM integrated in our app, which has APNS integrated out of the box, so we are receiving our normal notifications just fine on both Android and iOS. It's just this CleverTap setup for iOS notifications that isn't working.

I have provided screenshots and code below.

As a side note, If you want this plugin to be purely a Flutter plugin without requiring iOS or Android knowhow, why not just use FCM for iOS notifications as well? FCM already has APNS integration out of the box, which Flutter developers use.


The notifications are sent correctly
Screenshot 2021-11-14 at 10 48 28 2

AppDelegate.swift

import UIKit
import Flutter
import CleverTapSDK
import clevertap_plugin

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    
    CleverTap.autoIntegrate()
    CleverTapPlugin.sharedInstance()?.applicationDidLaunch(options: launchOptions)
    
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }

    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

}

main.dart (I've basically just copied what you have in your example)

@override
void initState() {
  super.initState();
  initPlatformState();
  activateCleverTapFlutterPluginHandlers();
  CleverTapPlugin.setDebugLevel(3);
  // CleverTapPlugin.createNotificationChannel("fluttertest", "Flutter Test", "Flutter Test", 3, true); // We already have an Android notification channel set up
  CleverTapPlugin.initializeInbox();
  CleverTapPlugin.registerForPush(); //only for iOS
}

Future<void> initPlatformState() async {
  if (!mounted) return;
}

void activateCleverTapFlutterPluginHandlers() {
  _clevertapPlugin = CleverTapPlugin();
  _clevertapPlugin.setCleverTapPushAmpPayloadReceivedHandler(pushAmpPayloadReceived);
  _clevertapPlugin.setCleverTapPushClickedPayloadReceivedHandler(pushClickedPayloadReceived);
  _clevertapPlugin.setCleverTapInAppNotificationDismissedHandler(inAppNotificationDismissed);
  _clevertapPlugin.setCleverTapProfileDidInitializeHandler(profileDidInitialize);
  _clevertapPlugin.setCleverTapProfileSyncHandler(profileDidUpdate);
  _clevertapPlugin.setCleverTapInboxDidInitializeHandler(inboxDidInitialize);
  _clevertapPlugin.setCleverTapInboxMessagesDidUpdateHandler(inboxMessagesDidUpdate);
  _clevertapPlugin.setCleverTapDisplayUnitsLoadedHandler(onDisplayUnitsLoaded);
  _clevertapPlugin.setCleverTapInAppNotificationButtonClickedHandler(inAppNotificationButtonClicked);
  _clevertapPlugin.setCleverTapInboxNotificationButtonClickedHandler(inboxNotificationButtonClicked);
  _clevertapPlugin.setCleverTapFeatureFlagUpdatedHandler(featureFlagsUpdated);
  _clevertapPlugin.setCleverTapProductConfigInitializedHandler(productConfigInitialized);
  _clevertapPlugin.setCleverTapProductConfigFetchedHandler(productConfigFetched);
  _clevertapPlugin.setCleverTapProductConfigActivatedHandler(productConfigActivated);
}

void inAppNotificationDismissed(Map<String, dynamic> map) {
  this.setState(() {
    print("inAppNotificationDismissed called");
  });
}

void inAppNotificationButtonClicked(Map<String, dynamic> map) {
  this.setState(() {
    print("inAppNotificationButtonClicked called = ${map.toString()}");
  });
}

void inboxNotificationButtonClicked(Map<String, dynamic> map) {
  this.setState(() {
    print("inboxNotificationButtonClicked called = ${map.toString()}");
  });
}

void profileDidInitialize() {
  this.setState(() {
    print("profileDidInitialize called");
  });
}

void profileDidUpdate(Map<String, dynamic> map) {
  this.setState(() {
    print("profileDidUpdate called");
  });
}

void inboxDidInitialize() {
  this.setState(() {
    print("inboxDidInitialize called");
    inboxInitialized = true;
  });
}

void inboxMessagesDidUpdate() {
  this.setState(() async {
    print("inboxMessagesDidUpdate called");
    int unread = await CleverTapPlugin.getInboxMessageUnreadCount();
    int total = await CleverTapPlugin.getInboxMessageCount();
    print("Unread count = " + unread.toString());
    print("Total count = " + total.toString());
  });
}

void onDisplayUnitsLoaded(List<dynamic> displayUnits) {
  this.setState(() async {
    List displayUnits = await CleverTapPlugin.getAllDisplayUnits();
    print("Display Units = " + displayUnits.toString());
  });
}

void featureFlagsUpdated() {
  print("Feature Flags Updated");
  this.setState(() async {
    bool booleanVar = await CleverTapPlugin.getFeatureFlag("BoolKey", false);
    print("Feature flag = " + booleanVar.toString());
  });
}

void productConfigInitialized() {
  print("Product Config Initialized");
  this.setState(() async {
    await CleverTapPlugin.fetch();
  });
}

void productConfigFetched() {
  print("Product Config Fetched");
  this.setState(() async {
    await CleverTapPlugin.activate();
  });
}

void productConfigActivated() {
  print("Product Config Activated");
  this.setState(() async {
    String stringvar = await CleverTapPlugin.getProductConfigString("StringKey");
    print("PC String = " + stringvar.toString());
    int intvar = await CleverTapPlugin.getProductConfigLong("IntKey");
    print("PC int = " + intvar.toString());
    double doublevar = await CleverTapPlugin.getProductConfigDouble("DoubleKey");
    print("PC double = " + doublevar.toString());
  });
}

void pushAmpPayloadReceived(Map<String, dynamic> map) {
  print("pushAmpPayloadReceived called");
  this.setState(() async {
    var data = jsonEncode(map);
    print("Push Amp Payload = " + data.toString());
    CleverTapPlugin.createNotification(data);
  });
}

void pushClickedPayloadReceived(Map<String, dynamic> map) {
  print("pushClickedPayloadReceived called");
  this.setState(() async {
    var data = jsonEncode(map);
    print("on Push Click Payload = " + data.toString());
  });
}
@CamronLDNF CamronLDNF changed the title Not receiving notifications when running Flutter app on iOS Not receiving push notifications when running Flutter app on iOS Nov 14, 2021
@Aditi3 Aditi3 self-assigned this Nov 15, 2021
@Aditi3
Copy link
Contributor

Aditi3 commented Nov 16, 2021

Hey @CamronLDNF This looks like an integration issue. Request you to raise a support ticket from the CleverTap dashboard so that we can further deep dive into this issue and assist you.

@CamronLDNF
Copy link
Author

@Aditi3 thanks, will do.

@bhargav6744
Copy link

@CamronLDNF interested to know what has worked for you as i am facing same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants