If anyone is interested, this (probably) turned out to be a bug and one has 
been filed. rdar://10280469

The way the system currently works is that it will ask for an admin password 
every time regardless of whether or not the SMJobBless function needs to 
install the helper tool or not. The bug is (probably) that a admin password 
request should not be made if the helper tool does not need to be installed 
(for example, it is already installed and has the same version as the one in 
the app bundle).

So, what this means is that the determination of whether or not the helper tool 
needs to be installed needs to be made before a call to SMJobBless and 
SMJobBless should only be called if it is already known the helper tool needs 
to be installed.

In my case, I only need to check whether the tool is installed 
(SMJobCopyDictionary handles this) and, if the tool is installed, whether or 
not it's version is older then the version of the tool in my app bundle.

Some (incomplete) code to check whether the tool is installed and what the 
versions are is below. 

There is another alternative to do a version check of the helper tool which is 
for the helper tool to receive a request for it's version and for it to send a 
version reply back. Personally, I like the method below, but wanted to mention 
this alternative as it may be the best path in some situations.


> ----------
> VVVVVVVVVV
> ----------
> NSDictionary* installedHelperJobData;
> 
> installedHelperJobData  = (NSDictionary*)SMJobCopyDictionary( 
> kSMDomainSystemLaunchd, (CFStringRef)@"com.apple.bsd.SMJobBlessHelper" );
> 
> NSString*       installedPath           = [[installedHelperJobData 
> objectForKey:@"ProgramArguments"] objectAtIndex:0];
> NSURL*          installedPathURL        = [NSURL 
> fileURLWithPath:installedPath];
> 
> NSDictionary*   installedInfoPlist      = 
> (NSDictionary*)CFBundleCopyInfoDictionaryForURL( (CFURLRef)installedPathURL );
> NSString*       installedBundleVersion  = [installedInfoPlist 
> objectForKey:@"CFBundleVersion"];
> NSInteger       installedVersion        = [installedBundleVersion 
> integerValue];
> 
> NSLog( @"installedVersion: %ld", (long)installedVersion );
> 
> NSBundle*       appBundle       = [NSBundle mainBundle];
> NSURL*          appBundleURL    = [appBundle bundleURL];
> 
> NSURL*          currentHelperToolURL    = [appBundleURL 
> URLByAppendingPathComponent:@"Contents/Library/LaunchServices/com.apple.bsd.SMJobBlessHelper"];
> NSDictionary*   currentInfoPlist        = 
> (NSDictionary*)CFBundleCopyInfoDictionaryForURL( 
> (CFURLRef)currentHelperToolURL );
> NSString*       currentBundleVersion    = [currentInfoPlist 
> objectForKey:@"CFBundleVersion"];
> NSInteger       currentVersion          = [currentBundleVersion integerValue];
> 
> NSLog( @"currentVersion: %ld", (long)currentVersion );
> ----------
> ^^^^^^^^^^
> ----------





On Sep 29, 2011, at 4:45 PM, Eric Gorr wrote:

> I cannot seem to locate any documentation on this, so hopefully someone can 
> confirm the behavior I am seeing with Apple's sample SMJobBless code located 
> at:
> 
> http://developer.apple.com/library/mac/#samplecode/SMJobBless/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010071
> 
> I was under the impression that it would only ask for an admin password if it 
> detected a that a new version of the helper tool needed to be installed.
> 
> However, this impression is apparently incorrect.
> 
> The behavior I am seeing under 10.6 is that if I launch the app for the first 
> time, it will ask for the password. If I launch almost immediately, it won't. 
> However, if I wait a long enough time, it will ask for the password again. 
> During all of this, the helper tool does not change.
> 
> Can anyone point to documentation that defines this as the correct behavior?
> 
> Thank you.
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to