Skip to content

Commit

Permalink
[Qt, OSX] fix usage of osx 10.8+ user notification center
Browse files Browse the repository at this point in the history
Currently Bitcoin-Qts support for OSX User Notification Center is broken. This pull will fix a known issue of non-official-apple-built apps having problems sending user notifications.
  • Loading branch information
jonasschnelli committed Nov 18, 2014
1 parent 8adf457 commit a7f2941
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/qt/macnotificationhandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@
#include "macnotificationhandler.h"

#undef slots
#import <objc/runtime.h>
#include <Cocoa/Cocoa.h>

// Add an obj-c category (extension) to return the expected bundle identifier
@implementation NSBundle(returnCorrectIdentifier)
- (NSString *)__bundleIdentifier
{
if (self == [NSBundle mainBundle]) {
return @"org.bitcoinfoundation.Bitcoin-Qt";
} else {
return [self __bundleIdentifier];
}
}
@end

void MacNotificationHandler::showNotification(const QString &title, const QString &text)
{
// check if users OS has support for NSUserNotification
Expand Down Expand Up @@ -63,7 +76,16 @@
MacNotificationHandler *MacNotificationHandler::instance()
{
static MacNotificationHandler *s_instance = NULL;
if (!s_instance)
if (!s_instance) {
s_instance = new MacNotificationHandler();

Class aPossibleClass = objc_getClass("NSBundle");
if (aPossibleClass) {
// change NSBundle -bundleIdentifier method to return a correct bundle identifier
// a bundle identifier is required to use OSXs User Notification Center
method_exchangeImplementations(class_getInstanceMethod(aPossibleClass, @selector(bundleIdentifier)),
class_getInstanceMethod(aPossibleClass, @selector(__bundleIdentifier)));
}
}
return s_instance;
}

0 comments on commit a7f2941

Please sign in to comment.