How do I prevent Alert when App is on Foreground with Incoming OneSignal Push Notification?

后端 未结 4 1856
失恋的感觉
失恋的感觉 2021-01-12 08:33

When my app is in the foreground, there is a alert that appears. How do I prevent this from appearing when receiving push notifications?

4条回答
  •  失恋的感觉
    2021-01-12 09:06

    I achieved it this way. Add the following code in your AppDelegate didFinishLaunchingWithOptions

    OneSignal.inFocusDisplayType = OSNotificationDisplayType.none
    

    on last line in

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
    
    OneSignal.inFocusDisplayType = OSNotificationDisplayType.none
    return true }
    

    we have these 3 options

    public enum OSNotificationDisplayType : UInt {
    
    
    /*Notification is silent, or app is in focus but InAppAlertNotifications are disabled*/
    case none
    
    
    /*Default UIAlertView display*/
    case inAppAlert
    
    
    /*iOS native notification display*/
    case notification
    }
    

    Here's OneSignal Documentation

提交回复
热议问题