You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift 4如何获取设备已安装应用名称列表?是否有替代方案?

Hey there! Great question—let’s break this down clearly, since there’s a common misconception here.

关于获取已安装应用列表的限制

First off: it’s not Swift 4 that removed this capability. The real story is that Apple started tightening privacy restrictions way back with iOS 9, and over subsequent versions, completely blocked third-party apps from accessing a full list of installed applications. The timing might have lined up with Swift 4’s release, but the change was driven by Apple’s privacy policies, not the Swift language itself. This is to protect users from apps collecting unnecessary personal data about their app usage.

可行的替代实现方式

Depending on what you actually need to achieve, there are a couple of valid, App Store-safe options:

  • Get info about your own app
    This is totally allowed and straightforward using the Bundle class. You can grab your app’s display name, version, and other metadata easily:

    let appDisplayName = Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String 
    ?? Bundle.main.infoDictionary?["CFBundleName"] as? String 
    ?? "Unknown App"
    print("My app name: \(appDisplayName)")
    
  • Check if a specific known app is installed
    If you only need to verify if a particular app (like WhatsApp, WeChat, etc.) is present on the device, you can use URL schemes. Here’s how:

    1. First, add the target app’s URL scheme to your Info.plist under the LSApplicationQueriesSchemes array. For example, to check for WeChat:
      <key>LSApplicationQueriesSchemes</key>
      <array>
          <string>weixin</string>
      </array>
      
    2. Then use this helper function to check if the app can be opened:
      func isTargetAppInstalled(scheme: String) -> Bool {
          guard let appURL = URL(string: scheme) else { return false }
          return UIApplication.shared.canOpenURL(appURL)
      }
      
      // Usage example
      if isTargetAppInstalled(scheme: "weixin://") {
          print("WeChat is installed!")
      } else {
          print("WeChat isn't on this device.")
      }
      

    Important note: You can only check schemes you’ve explicitly listed in Info.plist—you can’t use this to scan for all possible apps.

  • Enterprise/jailbroken environments (not for App Store)
    If you’re building an app for internal enterprise use or a jailbroken device, there are private APIs (like LSApplicationWorkspace) that can fetch installed app lists. But do not use these for App Store submissions—they’ll get your app rejected immediately, and Apple may ban your developer account. These methods are also unstable, as Apple can change or block private APIs at any time.

Final Note

For regular App Store apps, there’s no way to get a full list of installed applications anymore. Stick to the first two options above if you want to stay compliant with Apple’s rules.

内容的提问来源于stack exchange,提问作者Haibara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:13:38