PIVX Core  5.6.99
P2P Digital Currency
macnotificationhandler.mm
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin Core developers
2 // Copyright (c) 2015-2018 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
7 
8 #undef slots
9 #import <objc/runtime.h>
10 #include <Cocoa/Cocoa.h>
11 
12 // Add an obj-c category (extension) to return the expected bundle identifier
14 - (NSString *)__bundleIdentifier
15 {
16  if (self == [NSBundle mainBundle]) {
17  return @"io.pivx.Pivx-Qt";
18  } else {
19  return [self __bundleIdentifier];
20  }
21 }
22 @end
23 
24 void MacNotificationHandler::showNotification(const QString &title, const QString &text)
25 {
26  // check if users OS has support for NSUserNotification
27  if(this->hasUserNotificationCenterSupport()) {
28  NSUserNotification* userNotification = [[NSUserNotification alloc] init];
29  userNotification.title = title.toNSString();
30  userNotification.informativeText = text.toNSString();
31  [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: userNotification];
32  [userNotification release];
33  }
34 }
35 
37 {
38  Class possibleClass = NSClassFromString(@"NSUserNotificationCenter");
39 
40  // check if users OS has support for NSUserNotification
41  if(possibleClass!=nil) {
42  return true;
43  }
44  return false;
45 }
46 
47 
49 {
50  static MacNotificationHandler *s_instance = NULL;
51  if (!s_instance) {
52  s_instance = new MacNotificationHandler();
53 
54  Class aPossibleClass = objc_getClass("NSBundle");
55  if (aPossibleClass) {
56  // change NSBundle -bundleIdentifier method to return a correct bundle identifier
57  // a bundle identifier is required to use OSXs User Notification Center
58  method_exchangeImplementations(class_getInstanceMethod(aPossibleClass, @selector(bundleIdentifier)),
59  class_getInstanceMethod(aPossibleClass, @selector(__bundleIdentifier)));
60  }
61  }
62  return s_instance;
63 }
Macintosh-specific notification handler (supports UserNotificationCenter).
bool hasUserNotificationCenterSupport(void)
check if OS can handle UserNotifications
static MacNotificationHandler * instance()
void showNotification(const QString &title, const QString &text)
shows a 10.8+ UserNotification in the UserNotificationCenter