为了测试,我使用 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/