clevertap-ios-sdk
clevertap-ios-sdk copied to clipboard
In app notifications in SwiftUI Previews
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
Environment (please complete the following information):
- Xcode version: Xcode 14
- CleverTap SDK Version: 4.1.1
- Device: Preview
- OS: iOS 16
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?
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?()
}
})
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.
The problem still persists. It would also be great if there was a way to disable inAppNotifications when in Debug mode.