}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
- didReceiveNotificationResponse:(UNNotificationResponse *)response
- withCompletionHandler:(void (^)(void))completionHandler
+didReceiveNotificationResponse:(UNNotificationResponse *)response
+ withCompletionHandler:(void (^)(void))completionHandler
{
qCDebug(lcMacSystray()) << "Received notification with category identifier:" << response.notification.request.content.categoryIdentifier
<< "and action identifier" << response.actionIdentifier;
void registerNotificationCategories(const QString &localisedDownloadString) {
UNNotificationCategory * const generalCategory = [UNNotificationCategory
- categoryWithIdentifier:@"GENERAL"
- actions:@[]
- intentIdentifiers:@[]
- options:UNNotificationCategoryOptionCustomDismissAction];
+ categoryWithIdentifier:@"GENERAL"
+ actions:@[]
+ intentIdentifiers:@[]
+ options:UNNotificationCategoryOptionCustomDismissAction];
// Create the custom actions for update notifications.
UNNotificationAction * const downloadAction = [UNNotificationAction
- actionWithIdentifier:@"DOWNLOAD_ACTION"
- title:localisedDownloadString.toNSString()
- options:UNNotificationActionOptionNone];
+ actionWithIdentifier:@"DOWNLOAD_ACTION"
+ title:localisedDownloadString.toNSString()
+ options:UNNotificationActionOptionNone];
// Create the category with the custom actions.
UNNotificationCategory * const updateCategory = [UNNotificationCategory
- categoryWithIdentifier:@"UPDATE"
- actions:@[downloadAction]
- intentIdentifiers:@[]
- options:UNNotificationCategoryOptionNone];
+ categoryWithIdentifier:@"UPDATE"
+ actions:@[downloadAction]
+ intentIdentifiers:@[]
+ options:UNNotificationCategoryOptionNone];
// Create the custom action for talk notifications
UNTextInputNotificationAction * const talkReplyAction = [UNTextInputNotificationAction
- actionWithIdentifier:@"TALK_REPLY_ACTION"
- title:QObject::tr("Reply").toNSString()
- options:UNNotificationActionOptionNone
- textInputButtonTitle:QObject::tr("Reply").toNSString()
- textInputPlaceholder:QObject::tr("Send a Nextcloud Talk reply").toNSString()];
+ actionWithIdentifier:@"TALK_REPLY_ACTION"
+ title:QObject::tr("Reply").toNSString()
+ options:UNNotificationActionOptionNone
+ textInputButtonTitle:QObject::tr("Reply").toNSString()
+ textInputPlaceholder:QObject::tr("Send a Nextcloud Talk reply").toNSString()];
UNNotificationCategory * const talkReplyCategory = [UNNotificationCategory
- categoryWithIdentifier:@"TALK_MESSAGE"
- actions:@[talkReplyAction]
- intentIdentifiers:@[]
- options:UNNotificationCategoryOptionNone];
+ categoryWithIdentifier:@"TALK_MESSAGE"
+ actions:@[talkReplyAction]
+ intentIdentifiers:@[]
+ options:UNNotificationCategoryOptionNone];
[UNUserNotificationCenter.currentNotificationCenter setNotificationCategories:[NSSet setWithObjects:generalCategory, updateCategory, talkReplyCategory, nil]];
}
authOptions += UNAuthorizationOptionProvisional;
}
- [center requestAuthorizationWithOptions:(authOptions)
- completionHandler:^(BOOL granted, NSError * _Nullable error) {
- // Enable or disable features based on authorization.
- if (granted) {
- qCDebug(lcMacSystray) << "Authorization for notifications has been granted, can display notifications.";
- } else {
- qCDebug(lcMacSystray) << "Authorization for notifications not granted.";
- if(error) {
- const auto errorDescription = QString::fromNSString(error.localizedDescription);
- qCDebug(lcMacSystray) << "Error from notification center: " << errorDescription;
- }
+ [center requestAuthorizationWithOptions:(authOptions) completionHandler:^(BOOL granted, NSError * _Nullable error) {
+ // Enable or disable features based on authorization.
+ if (granted) {
+ qCDebug(lcMacSystray) << "Authorization for notifications has been granted, can display notifications.";
+ } else {
+ qCDebug(lcMacSystray) << "Authorization for notifications not granted.";
+ if (error) {
+ const auto errorDescription = QString::fromNSString(error.localizedDescription);
+ qCDebug(lcMacSystray) << "Error from notification center: " << errorDescription;
}
+ }
}];
}
static dispatch_once_t once;
dispatch_once(&once, ^{
- id delegate = [[NotificationCenterDelegate alloc] init];
- [center setDelegate:delegate];
+ id delegate = [[NotificationCenterDelegate alloc] init];
+ [center setDelegate:delegate];
});
}
content.categoryIdentifier = @"TALK_MESSAGE";
content.userInfo = [NSDictionary dictionaryWithObjects:@[accountNS, tokenNS, replyToNS] forKeys:@[@"account", @"token", @"replyTo"]];
- UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO];
+ UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO];
UNNotificationRequest * const request = [UNNotificationRequest requestWithIdentifier:@"NCTalkMessageNotification" content:content trigger:trigger];
[center addNotificationRequest:request withCompletionHandler:nil];