Commit bf294ee5 authored by Marvin Scholz's avatar Marvin Scholz Committed by Jean-Baptiste Kempf

osx_notifications: Check if user notifications classes exist to prevent crash on 10.7

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.
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent eed767fc
......@@ -87,6 +87,7 @@
NSMutableDictionary *registrationDictionary;
id lastNotification;
bool isInForeground;
bool hasNativeNotifications;
intf_thread_t *interfaceThread;
}
......@@ -299,6 +300,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;
......@@ -312,7 +319,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];
......@@ -344,8 +351,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
}
}
......@@ -409,7 +418,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];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment