How to Detect If App Was Launched by User Clicking Notification on MACos Now That Launchusernotificationuserinfokey Has Been Deprecated

Find list of Local Notification the app has already set

UIApplication has a property called scheduledLocalNotifications which returns an optional array containing elements of type UILocalNotification.

UIApplication.shared.scheduledLocalNotifications

NSUserNotification - How open the app when clicked

Just implement the NSUserNotificationCenterDelegate and define this method:

- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification

Example:

This is what I did in a "notifier" application.

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
NSRunAlertPanel([notification title], [notification informativeText], @"Ok", nil, nil);
}

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification
{
notifications=nil;
[tableView reloadData];
[center removeDeliveredNotification: notification];
}

When the notification is activated (click by the user) I just inform the user with a panel (I could use a hud window).In this case I immediately remove the delivered notification, but this is not what happens usually.The notification could stay there some time and be removed after 1/2 hours (it depends on the application that you are developing).

Detecting when a space changes in Spaces in Mac OS X

As Peter says, in 10.6 you can use the NSWorkSpace NSWorkspaceActiveSpaceDidChangeNotification to get a notification when the workspace changes.

You can then determine the current space using Quartz API, the kCGWindowWorkspace dictionary key holds the workspace.
e.g:

int currentSpace;
// get an array of all the windows in the current Space
CFArrayRef windowsInSpace = CGWindowListCopyWindowInfo(kCGWindowListOptionAll | kCGWindowListOptionOnScreenOnly, kCGNullWindowID);

// now loop over the array looking for a window with the kCGWindowWorkspace key
for (NSMutableDictionary *thisWindow in (NSArray *)windowsInSpace)
{
if ([thisWindow objectForKey:(id)kCGWindowWorkspace])
{
currentSpace = [thisWindow objectForKey(id)kCGWindowWorkspace] intValue];
break;
}
}

Alternatively you can get the Space using the private API, take a look at CGSPrivate.h which allows you to do this:

int currentSpace = 0;
CGSGetWorkspace(_CGSDefaultConnection(), ¤tSpace);

To change the screen resolution you'll want to look at Quartz services, for altering the volume this may be helpful.

How can I detect that the Shift key has been pressed?

From the Cocoa event handling guide:

The flagsChanged: method can be useful for detecting the pressing of modifier keys without any other key being pressed simultaneously. For example, if the user presses the Option key by itself, your responder object can detect this in its implementation of flagsChanged:.

More details can be found here.

The documentation for NSResponder also states the following:

flagsChanged:

Informs the receiver that the user has pressed or released a modifier key (Shift, Control, and so on).

-- (void)flagsChanged:(NSEvent *)theEvent

How to customise dialog message to prompt user for opening setting page

Before iOS 6 it was possible to set the purpose property on the CLLocationManager class but this has long been deprecated in favor of using the NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription strings in the Info.plist.

As far as I am aware there is no other way to replace this message. See original documentation

Apple Developer Documentation



Related Topics



Leave a reply



Submit