如何在app沙盒中使用“启动时登录”功能创建应用程序?
答案 0 :(得分:14)
谢谢CORY BOHON,他创建了以下教程:
http://martiancraft.com/blog/2015/01/login-items/
我将总结我所做的步骤:
添加StartAtLogin项目
将StartAtLoginHelper导入StartAtLogin项目
在StartAtLogin构建阶段,使用以下配置添加复制文件是StartAtLoginHelper:
3.1。目的地:包装
3.2。子路径:Contents / Library / LoginItems
在StartAtLoginHelper中,选择info.plist,添加行“Application is background only”= YES
在StartAtLoginHelper构建设置中,更改在发布中的跳过安装=是
在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];
NSArray * a = nil;
在StartAtLogin中,实现函数调用助手应用程序
SMLoginItemSetEnabled((__ bridge CFStringRef)@“com.giauhuynh.StartAtLoginHelper”,sender.state == NSOnState);
代码登录+启用App Sandbox
存档+将应用程序复制到“应用程序”文件夹并运行
和我的项目:
http://s000.tinyupload.com/?file_id=03236580059305049920
下面是一步一步(图示)
予。设置主应用
I.1。添加名为的主应用程序:StartAtLogin
I.2。添加帮助应用
I.2.1添加目标
I.2.2选择Cocoa Application
I.2.3名称:StartAtLoginHelper
I.2.4完全添加
I.3。将辅助应用程序添加到主应用程序:“Contents / Library / LoginItems”
I.3.1选择主应用程序的构建阶段
I.3.2添加新的构建阶段
I.3.3选择新的复制文件阶段
I.3.4复制文件部分仍为空白
I.3.5编辑目的地,子路径&添加帮助应用程序
I.4。写SMLoginItemSetEnabled
I.4.1选择主应用程序的MainMenu.xib
I.4.2添加名称为“在登录时开始”的复选框
I.4.3设定行动
I.4.4选择主应用程序的构建阶段
I.4.5导入ServiceManagement.framework
I.4.6实现SMLoginItemSetEnabled代码
II。设置帮助应用
II.1。申请表是背景=是
II.1.1选择帮助应用程序的信息
II.1.2添加行
II.1.3添加“应用程序仅后台”,然后设置值为“是”
II.2。在Release = YES
中跳过安装II.2.1选择帮助应用程序的构建设置,在搜索中输入单词“skip” 领域
II.2.2展开“跳过安装”部分
II.2.3设置“释放”行为“是”
II.3。删除窗口
II.3.1选择帮助应用程序的MainMenu.xib
II.3.2删除xib文件中的StartAtLoginHelper窗口
II.4。编写帮助代码
II.4.1选择帮助应用程序的ApplicationDelegate.m
II.4.2实施帮助代码
III。构建和测试
III.1。代码登录+ App Sandbox主应用程序和帮助应用程序
III.1.1代码登录主应用程序
III.1.1.1代码登录前
III.1.1.2代码登录后
III.1.2启用App Sandbox主应用程序
III.1.2.1启用App Sandbox之前
III.1.2.2启用App Sandbox后
III.1.3代码登录主应用程序
III.1.3.1代码登录前
III.1.3.2代码登录后
III.1.4启用App Sandbox主应用
III.1.4.1启用App Sandbox之前
III.1.4.2启用App Sandbox后
III.2。存档+将应用程序复制到“应用程序”文件夹。
III.2.1档案
III.2.1.1选择产品/存档
III.2.1.2等待Xcode归档
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应用程序复制到Applications文件夹
III.2.3打开应用程序
III.2.3.1打开StartAtLogin应用程序
III.2.3.2 StartAtLogin应用程序启动时的UI
III.2.3.3选中登录开始复选框
III.2.3.4注销(或关机,重启都可以)
III.2.3.5取消选中重新登录时重新打开窗口,然后注销