You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UNNotificationCategory添加限制问题:超过100个后部分类别失效

UNNotificationCategory 数量限制疑问

我通过以下代码设置通知类别,但当类别数量超过100个时,前100个Category ID能正常工作,剩下的完全无法生效。

func setNotificationCategories(application: UIApplication) {

    let center: UNUserNotificationCenter = UNUserNotificationCenter.current()
    center.delegate = self
    center.requestAuthorization(options: [.sound, .alert, .badge]) { _, error in

        if error != nil {
            return
        }

        var notificationCategories: Set<UNNotificationCategory> = []

        if let path = Bundle.main.path(forResource: "NotificationCategories", ofType: "plist"),
           let notificationCategoriesArray = NSArray(contentsOfFile: path) as? [[String: Any]] {

            for item in notificationCategoriesArray {

                if let categoryId = item["CategoryId"] as? String,
                   let buttonText = item["ButtonText"] as? String {

                    let notificationActions = [UNNotificationAction(identifier: "1", title: buttonText, options: [.foreground,
                                                                                                                      .authenticationRequired])]

                    let notificationCategory: UNNotificationCategory = UNNotificationCategory(identifier: categoryId,
                                                                                              actions: notificationActions,
                                                                                              intentIdentifiers: [],
                                                                                              options: .customDismissAction)
                    notificationCategories.insert(notificationCategory)
                }
            }
        }
        center.setNotificationCategories(notificationCategories)
        self.getNotificationSettings()
    }
}

示例plist文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
<array>
    <dict>
        <key>CategoryId</key>
        <string>1</string>
        <key>ButtonText</key>
        <string>check!</string>
    </dict>
    <dict>
        <key>CategoryId</key>
        <string>2</string>
        <key>ButtonText</key>
        <string>approve</string>
    </dict>
</array>
</plist> 

我查过Apple官方文档,没找到相关的限制说明,想确认是否可以添加超过100个UNNotificationCategory?


内容的提问来源于stack exchange,提问作者Emre YILMAZ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 07:12:44