[vlc-devel] [PATCH 1/1] osx_notifications: Check if user notifications classes exist to prevent crash on 10.7

epirat07 at gmail.com epirat07 at gmail.com
Fri Oct 23 13:11:29 CEST 2015


From: Marvin Scholz <epirat07 at gmail.com>

Add checks for NSUserNotification and NSUserNotificationCenter so we do not
use them on OS X 10.7 and below, to prevent VLC from crashing if it
is compiled on 10.8 or higher but ran on 10.7 or below.
---
 modules/notify/osx_notifications.m | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/modules/notify/osx_notifications.m b/modules/notify/osx_notifications.m
index 710ace0..5c2d01e 100644
--- a/modules/notify/osx_notifications.m
+++ b/modules/notify/osx_notifications.m
@@ -75,6 +75,7 @@
     NSMutableDictionary *registrationDictionary;
     id lastNotification;
     bool isInForeground;
+    bool hasNativeNotifications;
     intf_thread_t *interfaceThread;
 }
 
@@ -288,6 +289,12 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     // Start in background
     isInForeground = NO;
 
+    // Check for native notification support
+    Class userNotificationClass = NSClassFromString(@"NSUserNotification");
+    Class userNotificationCenterClass = NSClassFromString(@"NSUserNotificationCenter");
+    hasNativeNotifications = (userNotificationClass && userNotificationCenterClass) ? YES : NO;
+
+    lastNotification = nil;
     applicationName = nil;
     notificationType = nil;
     registrationDictionary = nil;
@@ -301,7 +308,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
     // Clear the remaining lastNotification in Notification Center, if any
     @autoreleasepool {
-        if (lastNotification) {
+        if (lastNotification && hasNativeNotifications) {
             [NSUserNotificationCenter.defaultUserNotificationCenter
              removeDeliveredNotification:(NSUserNotification *)lastNotification];
             [lastNotification release];
@@ -333,8 +340,10 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
         [GrowlApplicationBridge setGrowlDelegate:self];
 
 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
-        [[NSUserNotificationCenter defaultUserNotificationCenter]
-         setDelegate:(id<NSUserNotificationCenterDelegate>)self];
+        if (hasNativeNotifications) {
+            [[NSUserNotificationCenter defaultUserNotificationCenter]
+             setDelegate:(id<NSUserNotificationCenterDelegate>)self];
+        }
 #endif
     }
 }
@@ -398,7 +407,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
                                            isSticky:NO
                                        clickContext:nil
                                          identifier:@"VLCNowPlayingNotification"];
-        } else {
+        } else if (hasNativeNotifications) {
 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
             // Make the OS X notification and string
             NSUserNotification *notification = [NSUserNotification new];
-- 
2.2.1



More information about the vlc-devel mailing list