当我的应用程序位于前台时,会出现一条警报。如何防止在接收推送通知时出现此问题?如何使用传入的OneSignal推送通知在应用程序处于前景时防止警报?
6
A
回答
7
在你的AppDelegate
didFinishLaunchingWithOptions
方法,你必须添加kOSSettingsKeyInAppAlerts = NO
[OneSignal initWithLaunchOptions:launchOptions appId:ONESIGNAL_APPID handleNotificationReceived:nil handleNotificationAction:nil
settings:@{kOSSettingsKeyInAppAlerts:@NO}];
3
默认情况下,OneSignal在应用程序失焦时显示通知作为警报对话框。要将此通票kOSSettingsKeyInFocusDisplayOption
更改为值OSNotificationDisplayTypeNotification
或OSNotificationDisplayTypeNone
,并将其设置为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
}
相关问题
- 1. 如何防止传入OneSignal通知的警报?
- 2. 如何仅在应用程序处于前景时抑制推送Toast通知?
- 3. ios:禁用应用程序焦点时的警报通知(OneSignal)
- 4. 如何在应用程序处于前景或背景时打印出推送通知?
- 5. 在watchOS应用程序处于前台时处理推送通知?
- 6. 从推送通知的警报视图启动应用程序
- 7. iOS应用程序在本机警报关闭时发送推送通知
- 8. 使用Onesignal错误推送通知
- 9. 推送通知警报处理
- 10. 如何处理IOS推送通知时,应用程序是在前台?
- 11. 如何在我的应用程序处于前景时关闭通知图标?
- 12. 使用OneSignal丢失Ionic应用程序中的推送通知权利问题
- 13. 当推送通知进入时的警报序列
- 14. 如何使用OneSignal发送自定义声音推送通知?
- 15. 如何在应用程序关闭时发送推送通知?
- 16. OneSignal推送通知 - 关于WP8.1
- 17. 推送通知在实时iOS应用程序上停止
- 18. 当应用程序在前台时未收到推送通知
- 19. iOS - 用户终止应用程序时检测推送通知
- 20. 想要同时使用基于应用程序状态的无声推送通知和远程推送通知
- 21. 如何防止重新安装后推送通知到应用程序?
- 22. 应用程序终止时的推送通知
- 23. 解析SDK iOS - 推送通知仅在应用程序处于前景时才会显示
- 24. 如何阻止Android上的Onesignal推送通知?
- 25. 如何停止推送通知自动打开应用程序?
- 26. 推迟显示推送通知警报
- 27. 在应用程序处于后台时修改android中的firebase推送通知
- 28. 显示推送通知即使应用程序在Ionic Ios中处于前景(运行)
- 29. 如何在应用程序关闭时接收推送通知?
- 30. 在Ionic 2应用程序中接收OneSignal背景通知
注意'kOSSettingsKeyInAppAlerts'现不推荐使用,应该使用'kOSSettingsKeyInFocusDisplayOption' d。 – jkasten