美文网首页
swift 友盟推送(umPush)

swift 友盟推送(umPush)

作者: CSCloud | 来源:发表于2019-05-11 10:53 被阅读0次

基于官方文档:

1. 推送配置
// 友盟推送配置
    func umPushConfig()  {
        // push组件基本功能配置
        let entity = UMessageRegisterEntity.init()
        //type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
        entity.types = Int(UMessageAuthorizationOptions.badge.rawValue|UMessageAuthorizationOptions.sound.rawValue|UMessageAuthorizationOptions.alert.rawValue)
        if #available(iOS 10.0, *) {
            let action1 = UNNotificationAction.init(identifier: "action1_identifier", title: "打开应用", options: .foreground)
            let action2 = UNNotificationAction.init(identifier: "action2_identifier", title: "忽略", options: .foreground)
            //UNNotificationCategoryOptionNone
            //UNNotificationCategoryOptionCustomDismissAction  清除通知被触发会走通知的代理方法
            //UNNotificationCategoryOptionAllowInCarPlay       适用于行车模式
            let category1 = UNNotificationCategory.init(identifier: "category1", actions: [action1, action2], intentIdentifiers: [], options: .customDismissAction)
            let categories = NSSet.init(objects: category1)
            entity.categories = (categories as! Set<AnyHashable>)
            UNUserNotificationCenter.current().delegate = self
            UMessage.registerForRemoteNotifications(launchOptions: CSCConfig.sharedInstance.lauchOptions, entity: entity) { (granted, error) in
                if granted {
                    
                } else {
                    
                }
            }
            
        } else {
            // Fallback on earlier versions
            let action1 = UIMutableUserNotificationAction.init()
            action1.identifier = "action1_identifier"
            action1.title = "打开应用"
            action1.activationMode = .foreground
            let action2 = UIMutableUserNotificationAction.init()
            action2.identifier = "action2_identifier"
            action2.title = "忽略"
            action2.activationMode = .background //当点击的时候不启动程序,在后台处理
            action2.isAuthenticationRequired = true //需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
            action2.isDestructive = true
            let actionCategory1 = UIMutableUserNotificationCategory.init()
            actionCategory1.identifier = "category1" // 这组动作的唯一标示
            actionCategory1.setActions([action1, action2], for: .default)
            let categories = NSSet.init(objects: actionCategory1)
            entity.categories = (categories as! Set<AnyHashable>)
        }
    }
2. 获取deviceToken
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let device = NSData.init(data: deviceToken)
        let device_Token = device.description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "")
        CLog(item: "deviceToken: \(device_Token)")
    }

相关文章

  • swift 友盟推送(umPush)

    基于官方文档: 1. 推送配置 2. 获取deviceToken

  • swift2.0下集成友盟推送功能

    友盟IOS版本的推送之前是基于OBJC写的,友盟官方提供的API也是基于OBJC。而swift2.0下集成友盟推...

  • Swift 集成友盟推送

    1、前期准备 集成之前, 请在http://push.umeng.com/申请开通【友盟+】消息推送服务。下载 U...

  • iOS 友盟推送--关键点/核心点

    |:-| totem iOS集成友盟推送 1.iOS集成“友盟推送”后,友盟服务响应的deviceToken = ...

  • iOS 推送以及小红点

    思路: 1.设置友盟推送相关内容 // 友盟推送相关内容设置 - (void)setUMengPushMessag...

  • 友盟推送

    最近公司项目集成推送功能,相互比较之后选择了友盟推送。由于之前一直没有接触过推送,这次集成也算是踩了不少坑,写下来...

  • 友盟推送

    iOS收到推送后,跳转到某一页面 最近刚好有个项目,向指定用户推送订购信息、物品状态等等。 给大家讲一点常识,友盟...

  • 友盟推送

    友盟推送 推送不好用解决办法: 检查device_token。同一部测试机跑bundle id不同的程序所产生的d...

  • Swift-友盟分享UI面板之坑

    Swift桥接友盟,希望调整面板标题顺序,直接填写枚举对应数字即可: 友盟之swift坑,已踩。

  • iOS10.0 Swift 远程推送通知教程

    前言:最近在做远程推送的开发,学习了友盟的远程推送,和网上查阅到的OC版本的资料,但是没有查阅到有关swift 远...

网友评论

      本文标题:swift 友盟推送(umPush)

      本文链接:https://www.haomeiwen.com/subject/bitxaqtx.html