• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa App daemon with NSPanel
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa App daemon with NSPanel


  • Subject: Re: Cocoa App daemon with NSPanel
  • From: Matt Jaffa <email@hidden>
  • Date: Fri, 16 Jan 2004 09:56:52 -0700

Can anyone point me to a good example of using CFUserNotificationCreate
and then receiving the response of that call. Or write a quick
example, or fix this code to let me do it right. Code below.
I searched the archives and found an example, but it is not running
right.

Thanks,
Matt


SInt32 notiErr;
CFStringRef keys[2];
CFStringRef values[2];
CFDictionaryRef aDict;

CFOptionFlags responseFlags;
SInt32 resultInt;

// Create dictionary for notification call
keys[0] = kCFUserNotificationAlertMessageKey;
keys[1] = kCFUserNotificationDefaultButtonTitleKey;
values[0] = CFSTR("Tis a message!");
values[1] = CFSTR("Okey dokey");
aDict = CFDictionaryCreate(NULL, (void *)keys, (void
*)values, 2, &kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFShow(aDict);

bool gAlertIsUp = FALSE;
CFUserNotificationRef gUserNotification = NULL;

for ( ; ; ) {
//if flag off, put up alert
if ( gAlertIsUp== FALSE) {
gAlertIsUp = TRUE;
gUserNotification =
CFUserNotificationCreate(NULL, 15,
kCFUserNotificationCautionAlertLevel, &notiErr, aDict);
printf("notiErr = %ld\n", notiErr);
printf("Calling ReceiveResp\n");
resultInt =
CFUserNotificationReceiveResponse(gUserNotification, 10,
&responseFlags);
CFStringRef Trying;
Trying = CFSTR("Trying");

CFUserNotificationDisplayNotice(30,kCFUserNotificationCautionAlertLevel,
NULL,NULL,NULL,Trying,Trying,Trying);

printf("Response was %ld", resultInt);
gAlertIsUp = FALSE;
CFRelease(gUserNotification);

}
}
CFRelease(aDict);


On Jan 16, 2004, at 12:56 AM, Ryan McGann wrote:

> On Jan 15, 2004, at 10:00 PM, email@hidden wrote:
>
>> Yeah
>>
>> by daemon i mean that it is going to be started up as a Startup Item
>>
>> since it will be a daemon, i need a way of in my main function
>> being able to use my nib files and the @implementations etc.
> Using Cocoa (and therefore nib files, AppKit, and the like) from a
> daemon process that is started via StartupItems is not
> supported...actually, I don't think it'll work at all. StartupItem
> processes can only link to certain low-level frameworks, and the Cocoa
> or AppKit frameworks are not one of them. You can link to Foundation,
> CoreFoundation, CoreServices, the standard system libraries like
> libSystem, and some other frameworks (there is a final "approved" list
> in the works I believe). But not the high level Cocoa or Carbon
> frameworks.
>
>> I know i can use CFUserNotification, but i built a sophsticated
>> nib
>> files using panels and need somehow to call these objective-c nib
>> stuff from within main
> Well you don't have to use CFUserNotification, but you definitely
> cannot show the UI from inside your daemon. If you don't want to use
> CFUserNotification, you you can launch a helper Cocoa application that
> you send messages to from your daemon, and ask it to display the
> alerts when appropriate. However, there are some restrictions on when
> you can launch this "helper" process, and those restrictions have
> changed between Jaguar and Panther. Basically under Jaguar, you must
> wait until a user has logged in until you can launch the helper
> process.
>
> There's been numerous discussions on this topic in the past. Search
> the archives for instructions on how to obtain the LoginItems API,
> which will show you how to have your helper process launched
> automatically.
>
> Ryan
>
> Arguing with an engineer is like wrestling with a pig in mud.
> After a while, you realize the pig is enjoying it.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Cocoa App daemon with NSPanel (From: Ryan McGann <email@hidden>)

  • Prev by Date: NSController design question
  • Next by Date: NSBorderlessWindowMask shadows
  • Previous by thread: Re: Cocoa App daemon with NSPanel
  • Next by thread: Frame Information (Backtrace)
  • Index(es):
    • Date
    • Thread