SMLoginItemSetEnabled - Start by Login with Sandboxed App - Xcode 6.3 (Illustration)

How do I create an app with Start at Login when the app is isolated?

+3


source to share


1 answer


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;

  1. In StartAtLogin, implement a function call call app

    SMLoginItemSetEnabled ((__ bridge CFStringRef) @ "com.giauhuynh.StartAtLoginHelper", sender.state == NSOnState);

  2. Enter code + enable Sandbox app

  3. 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 enter image description here

I.2. Add helper application

I.2.1 Add target enter image description here

I.2.2 Select Cocoa Application enter image description here

I.2.3 Name: StartAtLoginHelper enter image description here

I.2.4 Add completely enter image description here

I.3. add helper app to main app: "Contents / Library / LoginItems"

I.3.1 Selecting milestones for creating applications enter image description here

I.3.2 Add a new build phase enter image description here

I.3.3. Select "New phase of copy files" enter image description here

I.3.4. The Copy Files section is still empty. enter image description here

I.3.5. Editing the destination, subdirectory and adding the helper application. enter image description here

I.4. SMLoginItemSetEnabled entry

I.4.1 Select main applications MainMenu.xib enter image description here

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

I.4.3 Set action enter image description here

I.4.4 Selection of basic applications Phase assembly enter image description here

I.4.5 Importing ServiceManagement.framework enter image description here

I.4.6 Inject SMLoginItemSetEnabled code enter image description here

II. Setting up the helper application

II.1. App background = YES

II.1.1 Select helper applications enter image description here

II.1.2 Add line enter image description here

II.1.3 Add "Application for background only", then set to "YES", enter image description here

II.2. Skip installation to Release = YES

II.2.1 Select Helper Applications Build Settings, enter the word "skip" in the search box enter image description here

II.2.2 Expand the "Skip installation" section enter image description here

II.2.3. String "Release" - "YES" enter image description here



II.3. Delete window

II.3.1 Select Helper Applications MainMenu.xib enter image description here

II.3.2. Delete the StartAtLoginHelpers window in the xib. enter image description here

II.4. Create helper code

II.4.1 Select helper applications ApplicationDelegate.m enter image description here

II.4.2 Implement helper code enter image description here

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 enter image description here

III.1.1.2 After entering the code enter image description here

III.1.2 Enable Main Application Sandbox Application

III.1.2.1 Before enabling the Sandbox application enter image description here

III.1.2.2 After Enable App Sandbox enter image description here

III.1.3 Entering the code in the main application

III.1.3.1 Before entering the code enter image description here

III.1.3.2 After entering the code enter image description here

III.1.4 Enable Main Application Sandbox Application

III.1.4.1 Before starting the Sandbox application enter image description here

III.1.4.2 After Enable App Sandbox enter image description here

III.2. Archive + Copy the application to the Applications folder.

III.2.1 Archive

III.2.1.1 Select product / archive enter image description here

III.2.1.2 Waiting for Xcode Archive enter image description here

III.2.1.3 "" enter image description here

III.2.1.4 "" Mac enter image description here

III.2.1.5 " " enter image description here

III.2.1.6 StartAtLogin enter image description here

III.2.2 ""

III.2.2.1 StartAtLogin enter image description here

III.2.2.2 StartAtLogin "" enter image description here

III.2.3

III.2.3.1 StartAtLogin enter image description here

III.2.3.2 StartAtLogin enter image description here

III.2.3.3 " " enter image description here

III.2.3.4 ( , ) enter image description here

III.2.3.5 " ", " " enter image description here

+11









All Articles