SMLoginItemSetEnabled - 从App Sandboxed登录开始 - Xcode 6.3(插图)

时间:2015-06-02 04:38:18

标签: objective-c xcode macos cocoa

如何在app沙盒中使用“启动时登录”功能创建应用程序?

1 个答案:

答案 0 :(得分:14)

谢谢CORY BOHON,他创建了以下教程:

http://martiancraft.com/blog/2015/01/login-items/

我将总结我所做的步骤:

  1. 添加StartAtLogin项目

  2. 将StartAtLoginHelper导入StartAtLogin项目

  3. 在StartAtLogin构建阶段,使用以下配置添加复制文件是StartAtLoginHelper:

    3.1。目的地:包装

    3.2。子路径:Contents / Library / LoginItems

  4. 在StartAtLoginHelper中,选择info.plist,添加行“Application is background only”= YES

  5. 在StartAtLoginHelper构建设置中,更改在发布中的跳过安装=是

  6. 在StartAtLoginHelper中,实现帮助程序代码

    NSArray * pathComponents = [[[NSBundle mainBundle] bundlePath] pathComponents]; pathComponents = [pathComponents subarrayWithRange:NSMakeRange(0,[pathComponents count] - 4)]; NSString * path = [NSString pathWithComponents:pathComponents]; [[NSWorkspace sharedWorkspace] launchApplication:path]; [NSApp终止:nil];

  7. NSArray * a = nil;

    1. 在StartAtLogin中,实现函数调用助手应用程序

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

    2. 代码登录+启用App Sandbox

    3. 存档+将应用程序复制到“应用程序”文件夹并运行

    4. 和我的项目:

      http://s000.tinyupload.com/?file_id=03236580059305049920

      下面是一步一步(图示)

      予。设置主应用

      I.1。添加名为的主应用程序:StartAtLogin enter image description here

      I.2。添加帮助应用

      I.2.1添加目标 enter image description here

      I.2.2选择Cocoa Application enter image description here

      I.2.3名称:StartAtLoginHelper enter image description here

      I.2.4完全添加 enter image description here

      I.3。将辅助应用程序添加到主应用程序:“Contents / Library / LoginItems”

      I.3.1选择主应用程序的构建阶段 enter image description here

      I.3.2添加新的构建阶段 enter image description here

      I.3.3选择新的复制文件阶段 enter image description here

      I.3.4复制文件部分仍为空白 enter image description here

      I.3.5编辑目的地,子路径&添加帮助应用程序 enter image description here

      I.4。写SMLoginItemSetEnabled

      I.4.1选择主应用程序的MainMenu.xib enter image description here

      I.4.2添加名称为“在登录时开始”的复选框 enter image description here

      I.4.3设定行动 enter image description here

      I.4.4选择主应用程序的构建阶段 enter image description here

      I.4.5导入ServiceManagement.framework enter image description here

      I.4.6实现SMLoginItemSetEnabled代码 enter image description here

      II。设置帮助应用

      II.1。申请表是背景=是

      II.1.1选择帮助应用程序的信息 enter image description here

      II.1.2添加行 enter image description here

      II.1.3添加“应用程序仅后台”,然后设置值为“是” enter image description here

      II.2。在Release = YES

      中跳过安装

      II.2.1选择帮助应用程序的构建设置,在搜索中输入单词“skip” 领域 enter image description here

      II.2.2展开“跳过安装”部分 enter image description here

      II.2.3设置“释放”行为“是” enter image description here

      II.3。删除窗口

      II.3.1选择帮助应用程序的MainMenu.xib enter image description here

      II.3.2删除xib文件中的StartAtLoginHelper窗口 enter image description here

      II.4。编写帮助代码

      II.4.1选择帮助应用程序的ApplicationDelegate.m enter image description here

      II.4.2实施帮助代码 enter image description here

      III。构建和测试

      III.1。代码登录+ App Sandbox主应用程序和帮助应用程序

      III.1.1代码登录主应用程序

      III.1.1.1代码登录前 enter image description here

      III.1.1.2代码登录后 enter image description here

      III.1.2启用App Sandbox主应用程序

      III.1.2.1启用App Sandbox之前 enter image description here

      III.1.2.2启用App Sandbox后 enter image description here

      III.1.3代码登录主应用程序

      III.1.3.1代码登录前 enter image description here

      III.1.3.2代码登录后 enter image description here

      III.1.4启用App Sandbox主应用

      III.1.4.1启用App Sandbox之前 enter image description here

      III.1.4.2启用App Sandbox后 enter image description here

      III.2。存档+将应用程序复制到“应用程序”文件夹。

      III.2.1档案

      III.2.1.1选择产品/存档 enter image description here

      III.2.1.2等待Xcode归档 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应用程序复制到Applications文件夹 enter image description here

      III.2.3打开应用程序

      III.2.3.1打开StartAtLogin应用程序 enter image description here

      III.2.3.2 StartAtLogin应用程序启动时的UI 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