Skip to content
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

In app notifications in SwiftUI Previews #194

Open
brurend opened this issue Sep 14, 2022 · 4 comments
Open

In app notifications in SwiftUI Previews #194

brurend opened this issue Sep 14, 2022 · 4 comments
Assignees

Comments

@brurend
Copy link

brurend commented Sep 14, 2022

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):

  • Xcode version: Xcode 14
  • CleverTap SDK Version: 4.1.1
  • Device: Preview
  • OS: iOS 16
@kushCT
Copy link
Contributor

kushCT commented Sep 15, 2022

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
Copy link
Author

brurend commented Sep 15, 2022

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
Copy link
Contributor

kushCT commented Sep 15, 2022

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
Copy link
Author

brurend commented Oct 13, 2022

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

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

No branches or pull requests

2 participants