ios - 通知警报禁用 swift

标签 ios swift push-notification notifications onesignal

为了测试,我使用 OneSignal 服务在我的设备上发送推送通知,我在 AppDelegate 中以这种方式处理它:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        OneSignal.initWithLaunchOptions(launchOptions, appId: “[app ID]”)//this method I register device on apple server

        return true
    }

func application(application: UIApplication,
                       didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
                                                    fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void){

        print(“ARRIVED")
        handleNotificationContent()// it’s not important for my question
}

我的问题是,当我收到通知并且应用程序在前台时,警报会自动显示,我不想显示它。 我该如何解决这个问题?

最佳答案

这段代码对我有用。

这适用于 Swift 2.2 和 Xcode 7.3.1

//Initialize One Signal using this code

OneSignal.initWithLaunchOptions(launchOptions, appId: oneSignalId, handleNotificationReceived: { (notification) in

     //Put your business logic here like adding an alert controller or posting an NSNotification.

}, handleNotificationAction: { (nil) in

     // This block gets called when the user reacts to a notification received

}, settings: [kOSSettingsKeyAutoPrompt : false, kOSSettingsKeyInAppAlerts: false])

     //set kOSSettingsKeyAutoPrompt to false

关于ios - 通知警报禁用 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39468909/

相关文章:

ios - 在iOS中实现动态uitableViewCell的最佳方法

ios - 如何在 iOS 上通过 UITextFields 进行枚举

ios - 当手指在该 View 内的 UIButton 上时,触摸时拖动 UIView 不起作用

swift - 如何将 Int16 音频样本数据转换为浮点音频样本数组

swift - 使用 FCM 的推送通知不适用于我的所有设备

ios - 我可以将 Xcode4 与两个未链接的独立 Apple 开发者帐户一起使用吗?

ios - OCUnit的测试用例类中是否需要在public接口(interface)中定义测试方法

arrays - Swift Array of Ints - 查找与前一个元素的差异大于 10 的索引

java - MIUI推送通知没有声音

node.js - 使用 IO 套接字和 nodejs 在 flutter 中推送通知