2016-10-20 40 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

相关问题