2016-10-20 81 views

回答

7

在你的AppDelegatedidFinishLaunchingWithOptions方法,你必須添加kOSSettingsKeyInAppAlerts = NO

[OneSignal initWithLaunchOptions:launchOptions appId:ONESIGNAL_APPID handleNotificationReceived:nil handleNotificationAction:nil 
          settings:@{kOSSettingsKeyInAppAlerts:@NO}]; 
+2

注意'kOSSettingsKeyInAppAlerts'現不推薦使用,應該使用'kOSSettingsKeyInFocusDisplayOption' d。 – jkasten

3

默認情況下,OneSignal在應用程序失焦時顯示通知作爲警報對話框。要將此通票kOSSettingsKeyInFocusDisplayOption更改爲值OSNotificationDisplayTypeNotificationOSNotificationDisplayTypeNone,並將其設置爲initWithLaunchOptions

6

對於雨燕3.0

// Initialize OngeSignal with Settings for Push Notifications 
    OneSignal.initWithLaunchOptions(launchOptions, appId: Constants.OneSignalAppID, handleNotificationReceived: nil, handleNotificationAction: { 
     (result) in 
     // Do Something with Notification Result 
    }, settings: [kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.none.rawValue]) 
0

我實現了這種方式。在最後一行AppDelegate中didFinishLaunchingWithOptions

OneSignal.inFocusDisplayType = OSNotificationDisplayType.none 

添加以下代碼

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { 

OneSignal.inFocusDisplayType = OSNotificationDisplayType.none 
return true } 

我們有這3個選項

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 
} 

這裏的OneSignal Documentation

相關問題