|
@@ -84,40 +84,38 @@ public extension UMManager {
|
|
|
//type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
|
|
|
_entity?.types = Int(UInt8(UMessageAuthorizationOptions.badge.rawValue)|UInt8(UMessageAuthorizationOptions.alert.rawValue)|UInt8(UMessageAuthorizationOptions.sound.rawValue))
|
|
|
|
|
|
- if #available(iOS 8.0, *) {
|
|
|
- if #available(iOS 10.0, *) {
|
|
|
+ if #available(iOS 10.0, *) {
|
|
|
+
|
|
|
+ let action1_ios10 = UNNotificationAction(identifier: "action1_identifier", title: "打开应用", options: UNNotificationActionOptions.foreground)
|
|
|
+ let action2_ios10 = UNNotificationAction(identifier: "action2_identifier", title: "忽略", options: UNNotificationActionOptions.foreground)
|
|
|
+
|
|
|
+ let category1_ios10 = UNNotificationCategory(identifier: "category1", actions: [action1_ios10,action2_ios10], intentIdentifiers: [], options: UNNotificationCategoryOptions.customDismissAction)
|
|
|
+ //UNNotificationCategoryOptionNone
|
|
|
+ //UNNotificationCategoryOptionCustomDismissAction 清除通知被触发会走通知的代理方法
|
|
|
+ //UNNotificationCategoryOptionAllowInCarPlay 适用于行车模式
|
|
|
+ let categories = NSSet(objects: category1_ios10)
|
|
|
+ _entity?.categories = (categories as! Set<AnyHashable>)
|
|
|
+ UNUserNotificationCenter.current().delegate = self
|
|
|
+
|
|
|
+ } else {
|
|
|
+ let action1 = UIMutableUserNotificationAction.init()
|
|
|
+ action1.identifier = "action1_identifier"
|
|
|
+ action1.title = "打开应用"
|
|
|
+ action1.activationMode = UIUserNotificationActivationMode.foreground;//当点击的时候启动程序
|
|
|
+
|
|
|
+ let action2 = UIMutableUserNotificationAction.init()
|
|
|
+ action2.identifier = "action2_identifier"
|
|
|
+ action2.title = "忽略"
|
|
|
+ action2.activationMode = UIUserNotificationActivationMode.background;//当点击的时候不启动程序,在后台处理
|
|
|
+ action2.isAuthenticationRequired = true;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
|
|
|
+ action2.isDestructive = true;
|
|
|
+
|
|
|
+ let actionCategory1 = UIMutableUserNotificationCategory.init()
|
|
|
+ actionCategory1.identifier = "category1"//这组动作的唯一标示
|
|
|
+ actionCategory1.setActions([action1,action2], for: UIUserNotificationActionContext.default)
|
|
|
+ let categories = NSSet(objects: actionCategory1)
|
|
|
+ _entity?.categories = (categories as! Set<AnyHashable>)
|
|
|
|
|
|
- let action1_ios10 = UNNotificationAction(identifier: "action1_identifier", title: "打开应用", options: UNNotificationActionOptions.foreground)
|
|
|
- let action2_ios10 = UNNotificationAction(identifier: "action2_identifier", title: "忽略", options: UNNotificationActionOptions.foreground)
|
|
|
-
|
|
|
- let category1_ios10 = UNNotificationCategory(identifier: "category1", actions: [action1_ios10,action2_ios10], intentIdentifiers: [], options: UNNotificationCategoryOptions.customDismissAction)
|
|
|
- //UNNotificationCategoryOptionNone
|
|
|
- //UNNotificationCategoryOptionCustomDismissAction 清除通知被触发会走通知的代理方法
|
|
|
- //UNNotificationCategoryOptionAllowInCarPlay 适用于行车模式
|
|
|
- let categories = NSSet(objects: category1_ios10)
|
|
|
- _entity?.categories = (categories as! Set<AnyHashable>)
|
|
|
- UNUserNotificationCenter.current().delegate = self
|
|
|
-
|
|
|
- } else {
|
|
|
- let action1 = UIMutableUserNotificationAction.init()
|
|
|
- action1.identifier = "action1_identifier"
|
|
|
- action1.title = "打开应用"
|
|
|
- action1.activationMode = UIUserNotificationActivationMode.foreground;//当点击的时候启动程序
|
|
|
-
|
|
|
- let action2 = UIMutableUserNotificationAction.init()
|
|
|
- action2.identifier = "action2_identifier"
|
|
|
- action2.title = "忽略"
|
|
|
- action2.activationMode = UIUserNotificationActivationMode.background;//当点击的时候不启动程序,在后台处理
|
|
|
- action2.isAuthenticationRequired = true;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
|
|
|
- action2.isDestructive = true;
|
|
|
-
|
|
|
- let actionCategory1 = UIMutableUserNotificationCategory.init()
|
|
|
- actionCategory1.identifier = "category1"//这组动作的唯一标示
|
|
|
- actionCategory1.setActions([action1,action2], for: UIUserNotificationActionContext.default)
|
|
|
- let categories = NSSet(objects: actionCategory1)
|
|
|
- _entity?.categories = (categories as! Set<AnyHashable>)
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//注册通知
|