當我的應用程序位於前臺時,會出現一條警報。如何防止在接收推送通知時出現此問題?如何使用傳入的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