I'm having the very devil of a time trying to get auto launch of sandboxed apps
to work, which is a real pity because I can think of quite a few apps for which
it would be rather handy. My latest attempt flings out the following error:
13/05/2013 21:42:09.962 com.apple.AppSandboxSMLoginItemEnabler[2112]: Attempt
to enable
file://localhost/Applications/DeviceInfo.app/Contents/Library/LoginItems/DeviceInfoLoginHelperApp.app/
without sandbox from sandboxed app
In this incarnation, I've signed and archived the helper app separately from
the main application that I'm trying to launch. This is really messing with my
mind - is anyone able to suggest what I'm doing wrong?
The login helper App is included in the main app, and the code in the main app
seems to function correctly:
- (IBAction)autoLaunchChange:(id)sender
{
// Creating helper app complete URL
NSURL *url = [[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]
URLByAppendingPathComponent:@"Contents/Library/LoginItems/DeviceInfoLoginHelperApp.app"];
// Registering helper app
if (LSRegisterURL((__bridge CFURLRef)url, true) != noErr)
{
NSLog(@"LSRegisterURL failed!");
}
if (!SMLoginItemSetEnabled
((CFStringRef)@"com.PaxSoftware.DeviceInfoLoginHelperApp", ([autoLaunch
state]==NSOnState)))
{
[
autoLaunch setState:NSOffState];
NSAlert *alert = [NSAlert alertWithMessageText:@"An error occurred"
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@"Couldn't set DeviceInfo Launch State."];
[alert runModal];
}
}
The login helper App has the following code (although this code never executes
- so this particular problem isn't here!):
- (
void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(@"Attempting Magic");
BOOL alreadyRunning = NO;
BOOL isActive = NO;
NSArray *running = [[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *app in running)
{
if ([[app bundleIdentifier] isEqualToString:@"com.PaxSoftware.DeviceInfo"])
{
alreadyRunning = YES;
isActive = [app isActive];
}
}
NSLog(@"alreadyRunning %d isActive %d ",alreadyRunning,isActive);
if (!alreadyRunning || !isActive)
{
NSString *path = [[NSBundle mainBundle] bundlePath];
NSArray *p = [path pathComponents];
NSMutableArray *pathComponents = [NSMutableArray arrayWithArray:p];
[pathComponents removeLastObject];
[pathComponents removeLastObject];
[pathComponents removeLastObject];
[pathComponents addObject:@"MacOS"];
[pathComponents
addObject:@"DeviceInfo"];
NSString *newPath = [NSString pathWithComponents:pathComponents];
NSLog(@"%@",newPath);
[[
NSWorkspace sharedWorkspace] launchApplication:newPath];
}
[NSApp terminate:nil];
}
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]