CleverTap / clevertap-ios-sdk

CleverTap iOS SDK
https://clevertap.com
MIT License
54 stars 52 forks source link

In app notifications in SwiftUI Previews #194

Open brurend opened 1 year ago

brurend commented 1 year ago

Describe the bug In app notifications are showing inside SwiftUI previews in all views. This seems to have started happening after updating to Xcode 14.

Expected behaviour In previews it shouldn't appear in app notifications.

Screenshots image

Environment (please complete the following information):

kushCT commented 1 year ago

Hi @brurend Can you please provide some steps or link us with an empty sample app with your issue so that we can be able to debug the issue better?

brurend commented 1 year ago

It seems to be happening at random, sometimes it does but sometimes it doesn't. That's how we initialize the SDK at AppDelegate, perhaps we are doing something wrong here?

UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .badge, .alert], completionHandler: { granted, _ in
            DispatchQueue.main.async { [weak self] in
                guard let self = self else { return }

                if granted {
                    UIApplication.shared.registerForRemoteNotifications()
                }
                CleverTap.autoIntegrate()
                CleverTap.sharedInstance()?.setInAppNotificationDelegate(self)
                completion?()
            }
        })
kushCT commented 1 year ago

Hello @brurend . Since we are using CleverTap.autoIntegrate(), The SDK is already supporting inApp notifications by calling inApp delegate methods on it's end, you don't need to manually call 'setInAppNotificationDelegate' method from your side. To initialize the SDK in App Delegate, please go to CleverTap iOS SDK Integration guide I am providing you a Swift sample code. Make sure to import CleverTapSDK .

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        CleverTap.autoIntegrate()
        registerForPush()
        return true
    }

func registerForPush() {
        // Register for Push notifications
        UNUserNotificationCenter.current().delegate = self
        // request Permissions
        UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .badge, .alert], completionHandler: {granted, error in
            if granted {
                DispatchQueue.main.async {
                    UIApplication.shared.registerForRemoteNotifications()
                }
            }
        })
    }

I hope this solves your issue.

brurend commented 1 year ago

The problem still persists. It would also be great if there was a way to disable inAppNotifications when in Debug mode.