SMLoginItemSetEnabled - Start by Login with Sandboxed App - Xcode 6.3 (Illustration)
Thanks CORY BOHON who created the following tutorial:
http://martiancraft.com/blog/2015/01/login-items/
I will take the following steps:
-
Add StartAtLogin Project
-
Importing StartAtLoginHelper into the StartAtLogin project
-
In StartAtLogin Build Phase add Copy Files - StartAtLoginHelper with below config:
3.1. Purpose: Wrap
3.2. Subpath: Contents / Library / LoginItems
-
In StartAtLoginHelper select info.plist, add the line "Application for background only" = YES
-
In the build settings StartAtLoginHelper change "Skip installation to Release = YES
-
In StartAtLoginHelper we implement the auxiliary code
NSArray * pathComponents = [[[NSBundle mainBundle] bundlePath] pathComponents]; pathComponents = [pathComponents subarrayWithRange: NSMakeRange (0, [pathComponents count] - 4)]; NSString * path = [NSString pathWithComponents: pathComponents]; [[NSWorkspace sharedWorkspace] launchApplication: path]; [NSApp terminate: nil];
NSArray * a = nil;
-
In StartAtLogin, implement a function call call app
SMLoginItemSetEnabled ((__ bridge CFStringRef) @ "com.giauhuynh.StartAtLoginHelper", sender.state == NSOnState);
-
Enter code + enable Sandbox app
-
Archive + Copy the application to the Applications folder and run
and my project:
http://s000.tinyupload.com/?file_id=03236580059305049920
Below is a step by step (with illustration)
I am. Setting up the main application
I.1. Add main app named: StartAtLogin

I.2. Add helper application
I.2.1 Add target

I.2.2 Select Cocoa Application

I.2.3 Name: StartAtLoginHelper

I.2.4 Add completely

I.3. add helper app to main app: "Contents / Library / LoginItems"
I.3.1 Selecting milestones for creating applications

I.3.2 Add a new build phase

I.3.3. Select "New phase of copy files"

I.3.4. The Copy Files section is still empty.

I.3.5. Editing the destination, subdirectory and adding the helper application.

I.4. SMLoginItemSetEnabled entry
I.4.1 Select main applications MainMenu.xib

I.4.2 Add a checkbox named "Start at Login" <T411>
I.4.3 Set action

I.4.4 Selection of basic applications Phase assembly

I.4.5 Importing ServiceManagement.framework

I.4.6 Inject SMLoginItemSetEnabled code

II. Setting up the helper application
II.1. App background = YES
II.1.1 Select helper applications

II.1.2 Add line

II.1.3 Add "Application for background only", then set to "YES",

II.2. Skip installation to Release = YES
II.2.1 Select Helper Applications Build Settings, enter the word "skip" in the search box

II.2.2 Expand the "Skip installation" section

II.2.3. String "Release" - "YES"

II.3. Delete window
II.3.1 Select Helper Applications MainMenu.xib

II.3.2. Delete the StartAtLoginHelpers window in the xib.

II.4. Create helper code
II.4.1 Select helper applications ApplicationDelegate.m

II.4.2 Implement helper code

III. Building and testing
III.1. Code point in Application Application and Main Application and Helper Application
III.1.1 Code Sign In Main Application
III.1.1.1 Before entering the code

III.1.1.2 After entering the code

III.1.2 Enable Main Application Sandbox Application
III.1.2.1 Before enabling the Sandbox application

III.1.2.2 After Enable App Sandbox

III.1.3 Entering the code in the main application
III.1.3.1 Before entering the code

III.1.3.2 After entering the code

III.1.4 Enable Main Application Sandbox Application
III.1.4.1 Before starting the Sandbox application

III.1.4.2 After Enable App Sandbox

III.2. Archive + Copy the application to the Applications folder.
III.2.1 Archive
III.2.1.1 Select product / archive

III.2.1.2 Waiting for Xcode Archive

III.2.1.3 ""

III.2.1.4 "" Mac

III.2.1.5 " "

III.2.1.6 StartAtLogin

III.2.2 ""
III.2.2.1 StartAtLogin

III.2.2.2 StartAtLogin ""

III.2.3
III.2.3.1 StartAtLogin

III.2.3.2 StartAtLogin

III.2.3.3 " "

III.2.3.4 ( , )

III.2.3.5 " ", " "
