When I obtain the basic information of notifications through the Notification source of Ancs, it is found that the EventFlagNegativeAction part of the EventFlags is missing =(1<<4) Always in the state of 1, whether it's phone calls, text messages, apps, or unconfigured UserNotifications. Why is this
ANCS EventFlagNegativeAction Always in the state of 1
EventFlagNegativeAction
will be sent IF the notification is configured as "actionable" and has a "dismiss" action button configured.
The article Declaring your actionable notification types explains how to add action buttons to notifications and configuring the action categories.
Argun Tekant / DTS Engineer / Core Technologies
But even if I added negative and positive actions according to the document, the data parsed by the receiving end still only contains negative behaviors,just like default behavior.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self setupNotificationCategories];
return YES;
}
- (void)setupNotificationCategories {
// 创建一个简单的动作
UNNotificationAction *actionAccept = [UNNotificationAction actionWithIdentifier:@"ACCEPT_ACTION"
title:@"ACCEPT"
options:UNNotificationActionOptionNone];
UNNotificationAction *actionDecline = [UNNotificationAction actionWithIdentifier:@"DECLINE_ACTION"
title:@"DECLINE"
options:UNNotificationActionOptionDestructive];
// 创建一个通知类别,包含上面的动作
UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"MEETING_INVITATION"
actions:@[actionAccept,actionDecline] // 可以添加多个动作
intentIdentifiers:@[] // 可以添加意图标识符,用于处理Siri等
options:UNNotificationCategoryOptionCustomDismissAction];
// 将类别添加到通知中心以便使用
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center setNotificationCategories:[NSSet setWithObject:category]];
}-(void)postLocalNotificationWithMessage:(NSString*)message identifier:(NSString*)identifier level:(int)level{
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
// 处理授权结果
if (granted) {
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = @"Notification Tag";
content.body = @"您有一条新消息";
content.categoryIdentifier = @"MEETING_INVITATION"; // 关键:绑定分类
content.userInfo = @{@"MEETING_ID" : @"meeting1",
@"USER_ID" : @"user1" };
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy/MM/dd HH:mm";
NSString *date = [formatter stringFromDate:[NSDate date]];
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:2 repeats:NO];
// 生成唯一标识符
NSString *uniqueID = [NSString stringWithFormat:@"dynaTagGroupNotification_%@_%@_%@", identifier, date, @(arc4random_uniform(1000))];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:uniqueID
content:content
trigger:trigger];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request
withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
// 成功添加
}
}];
};
}];
}The relevant code is as follows:
relevant environment
iphone 13pro
iOS 17.7
testing environment
nRF Connect && LightBlue for android
Thank you for all these details. This looks like something the Bluetooth team will need to look at to determine if the behavior is as designed for some reason, or this is unexpected, so it is best if you put all this info into bug report.
To file a bug report, you can use the Feedback Assistant.
If you have any questions about filing a bug report, take a look at Bug Reporting: How and Why?
Argun Tekant / DTS Engineer / Core Technologies