代码之家  ›  专栏  ›  技术社区  ›  Manngo

如何使用相同的BundleIdentifier清除应用程序

  •  0
  • Manngo  · 技术社区  · 4 年前

    我已经将应用程序复制到一个位置进行测试,然后删除了它。然而,我发现当我尝试这样的事情时:

    //  Current Application
        let id = Bundle.main.bundleIdentifier!
        let thisApp = NSRunningApplication.runningApplications(withBundleIdentifier: id).last!
    //  Get Bundle
        let bundleURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID)!
        guard let bundle = Bundle(url: bundleURL)
        else {
            print("oops! bundleURL: \(bundleURL)")
            return
        }
    

    通常 获取错误消息。看来 urlForApplication

    0 回复  |  直到 4 年前
        1
  •  0
  •   Leo Dabus    4 年前

    您可以获取正在运行的应用程序的列表,然后按其筛选绑定标识符,然后再次筛选不等于当前标识符的绑定标识符:

    let sameBundleIdentifiers = NSWorkspace.shared.runningApplications.filter({$0.bundleIdentifier == (Bundle.main.bundleIdentifier ?? "")})
    
    print("sameBundleIdentifiers", sameBundleIdentifiers.count)
    
    let filtered = sameBundleIdentifiers.filter {$0 != NSRunningApplication.current }