Close other apps in sandbox mode

40 篇文章 0 订阅
17 篇文章 0 订阅

参考: https://developer.apple.com/forums/thread/122020

例如:在KillerDemo 程序中 kill 掉 DemoA 程序

  • 测试代码
@IBAction func killAction(_ sender: Any) {
        
        let runingApps = NSRunningApplication.runningApplications(withBundleIdentifier: targetIDField.stringValue)
        
        runingApps.forEach { (app) in
            let bSuc = app.terminate()
//            let bSuc = kill(app.processIdentifier, SIGKILL)

            let printInfo = bSuc ? "kill app[\(app.bundleIdentifier ?? "")] sucessfullly" : "kill app[\(app.bundleIdentifier ?? "")] failed"
            print(printInfo)
        }
    }

1. KillerDemo 启用 sandbox时,无法直接 kill 掉别的进程

1.1 Case 1: KillerDemo 启用 sandbox , DemoA 未启用 sandbox

需要在 .entitlements 文件中配置信息。
在没有配置信息之前,是无法结束进程的。func kill(_: pid_t, _: Int32) -> Int32 也不行。
使用脚本,我没有试过,不过猜测也不行。

添加配置信息

  • com.apple.security.get-task-allow
  • com.apple.security.temporary-exception.apple-events

entitlements 如下:

<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.get-task-allow</key>
    <true/>
    <key>com.apple.security.temporary-exception.apple-events</key>
    <array>
        <string>com.apple.TextEdit</string>
    </array>
</dict>
</plist>

只要在com.apple.security.temporary-exception.apple-events 字段中添加的 bundle identifier 都可以 kill 掉了

1.1 Case 2: KillerDemo 启用 sandbox , DemoA也启用 sandbox

寻找方法中…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值