Try to use UserNotifications.
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
#include "manager.h"
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <QtMac>
|
||||
#import <UserNotifications/UserNotifications.h>
|
||||
|
||||
@interface NSUserNotification (CFIPrivate)
|
||||
- (void)set_identityImage:(NSImage*)image;
|
||||
@end
|
||||
#include <QApplication>
|
||||
|
||||
NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) {}
|
||||
NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) {
|
||||
|
||||
}
|
||||
|
||||
void NotificationsManager::postNotification(const QString& roomId,
|
||||
const QString& eventId,
|
||||
@@ -19,16 +18,37 @@ void NotificationsManager::postNotification(const QString& roomId,
|
||||
Q_UNUSED(eventId);
|
||||
Q_UNUSED(icon);
|
||||
|
||||
NSUserNotification* notif = [[NSUserNotification alloc] init];
|
||||
UNUserNotificationCenter* center =
|
||||
[UNUserNotificationCenter currentNotificationCenter];
|
||||
UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound;
|
||||
|
||||
notif.title = roomName.toNSString();
|
||||
notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString();
|
||||
notif.informativeText = text.toNSString();
|
||||
notif.soundName = NSUserNotificationDefaultSoundName;
|
||||
[center requestAuthorizationWithOptions:options
|
||||
completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
||||
if (!granted) {
|
||||
NSLog(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter]
|
||||
deliverNotification:notif];
|
||||
[notif autorelease];
|
||||
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:300
|
||||
repeats:NO];
|
||||
|
||||
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
|
||||
|
||||
content.title = roomName.toNSString();
|
||||
content.subtitle = QString("%1 sent a message").arg(senderName).toNSString();
|
||||
content.body = text.toNSString();
|
||||
content.sound = [UNNotificationSound defaultSound];
|
||||
|
||||
NSString *identifier = QApplication::applicationName().toNSString();
|
||||
|
||||
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier
|
||||
content:content trigger:trigger];
|
||||
|
||||
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
|
||||
if (error != nil) {
|
||||
NSLog(@"Something went wrong: %@",error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
// unused
|
||||
|
||||
Reference in New Issue
Block a user