iOS端Clevertap平台通知操作标题及深度链接配置方法咨询
关于Clevertap配置iOS通知操作及深度链接的问题解答
我来帮你一步步解决这两个关于Clevertap和iOS通知的问题:
1. 如何在Clevertap中为iOS通知配置操作标题及对应的深度链接?
配置分为Clevertap后台设置和iOS客户端适配两部分:
Clevertap后台操作步骤
- 登录Clevertap控制台,进入推送通知创建页面
- 在通知配置区域找到「Notification Actions」(通知操作)选项,点击添加操作按钮
- 为每个操作按钮设置操作标题(比如“查看详情”“立即处理”)
- 在操作的「Deep Link」字段中填写你的应用深度链接,可以是自定义URL Scheme(如
yourapp://order/detail?id=123)或者Universal Link - 确保为操作按钮关联对应的通知Category ID(这个ID需要和iOS客户端配置的一致)
iOS客户端适配
你需要在AppDelegate(或NotificationCenterDelegate)中处理通知操作的回调,解析Clevertap传递的深度链接并完成页面跳转:
import UserNotifications import CleverTapSDK func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { // 处理Clevertap通知回调 CleverTap.sharedInstance()?.handleNotificationResponse(response) // 解析深度链接 let userInfo = response.notification.request.content.userInfo if let deepLink = userInfo["ct_deep_link"] as? String { // 这里根据深度链接跳转对应页面 if let url = URL(string: deepLink) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } } completionHandler() }
2. iOS 11+的自定义操作项富通知,能否在Clevertap配置并实现动态操作按钮?
完全可以实现!Clevertap支持配置iOS的自定义通知操作项,并且能关联深度链接,最终实现类似短信、WhatsApp的通知面板动态操作按钮效果。
实现步骤:
第一步:iOS客户端注册通知Category
首先需要在App启动时注册对应的通知Category,确保和Clevertap后台配置的Category ID一致:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // 注册通知权限 UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in if granted { // 创建自定义操作 let viewAction = UNNotificationAction(identifier: "view_action", title: "查看订单", options: [.foreground]) let cancelAction = UNNotificationAction(identifier: "cancel_action", title: "取消订单", options: []) // 创建Category,ID要和Clevertap后台配置一致 let orderCategory = UNNotificationCategory(identifier: "order_notification", actions: [viewAction, cancelAction], intentIdentifiers: [], options: []) // 注册Category UNUserNotificationCenter.current().setNotificationCategories([orderCategory]) } } // 初始化Clevertap CleverTap.sharedInstance()?.autoIntegrate() return true }
第二步:Clevertap后台配置操作项
- 在创建推送通知时,找到「Notification Category」选项,选择你刚才注册的Category ID(比如
order_notification) - 在「Notification Actions」中添加对应操作按钮,分别设置标题、关联的动作标识符(要和iOS端注册的Action ID一致,比如
view_action),并填写对应的深度链接 - 完成配置后推送通知,iPhone的通知面板就会显示你设置的动态操作按钮
第三步:处理操作按钮的深度链接跳转
和第一个问题的客户端处理逻辑类似,在userNotificationCenter:didReceiveNotificationResponse:回调中,根据响应的actionIdentifier区分不同操作,再解析对应的深度链接完成跳转:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { CleverTap.sharedInstance()?.handleNotificationResponse(response) let actionID = response.actionIdentifier let userInfo = response.notification.request.content.userInfo switch actionID { case "view_action": if let deepLink = userInfo["ct_deep_link_view"] as? String { // 假设Clevertap中为该操作设置的深度链接存在这个字段 if let url = URL(string: deepLink) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } } case "cancel_action": // 处理取消订单的逻辑,比如调用接口更新订单状态 print("用户点击了取消订单按钮") default: break } completionHandler() }
这样配置完成后,用户收到Clevertap推送的通知时,就能在通知面板看到自定义的操作按钮,点击后直接触发对应的深度链接跳转或业务逻辑啦。
内容的提问来源于stack exchange,提问作者Viswa Bharath Dakka
相关产品推荐
相关产品推荐

