Curiously, with Monterey and subsequent macOS versions up to and including Sonoma, the Lazarus GUI program worked on some machines but not others for no reason I can determine (I have a stable of Mac minis :)
Anyway, while the Lazarus GUI version has this unreliability issue from Monterey onwards, my pure Pascal program below does not. It works on all machines and all macOS versions.
program badger;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
uses
CocoaAll;
type
{ TMyDelegate }
TMyDelegate = objcclass(NSObject)
public
procedure BadgeButtonClick(sender : id); message 'BadgeButtonClick:';
procedure UnBadgeButtonClick(sender : id); message 'UnBadgeButtonClick:';
end;
var
appName : NSString;
window : NSWindow;
myBadgeButton : NSButton;
myUnBadgeButton : NSButton;
myDelegate : TMyDelegate;
procedure TMyDelegate.BadgeButtonClick(sender : id);
begin
NSApp.dockTile.setBadgeLabel(NSStr('12'));
end;
procedure TMyDelegate.UnBadgeButtonClick(sender : id);
begin
NSApp.dockTile.setBadgeLabel(Nil);
end;
begin
// app and window creation
NSApp := NSApplication.sharedApplication;
NSApp.setActivationPolicy(NSApplicationActivationPolicyRegular);
appName := NSStr('Badger');
window := NSWindow.alloc.initWithContentRect_styleMask_backing_defer(NSMakeRect(0, 0, 200, 200),
NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask,
NSBackingStoreBuffered, False);
myDelegate := TMyDelegate.alloc.init;
// badge button
myBadgeButton := NSButton.alloc.initWithFrame(NSMakeRect(50, 100, 100, 50));
window.contentView.addSubview(myBadgeButton);
myBadgeButton.setTitle(NSSTR('Badge'));
myBadgeButton.setButtonType(NSMomentaryLightButton);
myBadgeButton.setBezelStyle(NSRoundedBezelStyle);
// unbadge button
myUnBadgeButton := NSButton.alloc.initWithFrame(NSMakeRect(50, 60, 100, 50));
window.contentView.addSubview(myUnBadgeButton);
myUnBadgeButton.setTitle(NSSTR('UnBadge'));
myUnBadgeButton.setButtonType(NSMomentaryLightButton);
myUnBadgeButton.setBezelStyle(NSRoundedBezelStyle);
// badge button event handler
myBadgeButton.setTarget(myDelegate);
myBadgeButton.setAction(ObjCSelector(myDelegate.BadgeButtonClick));
// unbadge button event handler
myUnBadgeButton.setTarget(myDelegate);
myUnBadgeButton.setAction(ObjCSelector(myDelegate.UnBadgeButtonClick));
// Window showing and app running
window.center;
window.setTitle(appName);
window.makeKeyAndOrderFront(Nil);
NSApp.activateIgnoringOtherApps(True);
NSApp.run;
end.
As to the UNUserNotificationCenter, this is currently not available in Lazarus (due to somewhat outdated Pascalised Cocoa headers), but thanks for responding!
Post
Replies
Boosts
Views
Activity
Upgrading to Monterey 12.1 made no difference. I also notice the App Store dock icon no longer shows a badge for apps to be updated, but the System Preferences dock icon does show when there's an system software update.
I have updated SampleD.c and attached it below.
SampleD.c - https://developer.apple.com/forums/content/attachment/034c454f-ea4e-403a-890c-c4206f0ee1c5
And now nearly five years later, it is still not updated, but it has been "archived" with no obvious replacement. The Apple documentation seems to be archived these days instead of being updated which is not helpful.
There appears to be no up-to-date high level documentation any more other than the Archive of unmaintained and out of date documentation which was actually useful.
Once upon a time Mac applications came with awesome Help Books - try finding any up-to-date documentation of that topic now! You have less than a snowball's chance in hell. Result: most developers now provide a PDF file instead or a link to a website than can disappear and may not be found in the Internet Archive. Sad.
Seems the Guides and sample code have been disappeared again. The Documentation page at https://developer.apple.com/documentation/ is next to useless.
The only useful information seems to be in the Archive of documentation that is no longer maintained and has no up to date version or replacement. <sigh/>