【问题标题】:Access Bundle Identifier of App in Custom Framework自定义框架中 App 的访问 Bundle Identifier
【发布时间】:2019-09-30 08:39:48
【问题描述】:

我正在设计一个 sdk,我会在某个时间点进行一些 url 调用。为此,我想要正在调用的应用程序的上下文。作为上下文,我想使用该 sdk 传递应用程序的包标识符。

SDK 是一些第三方应用程序将导入和使用的库形式。我有 UIViewController 的引用,它在第三方应用程序中调用 url 调用。我不知道只有 UIViewController 引用是否足够。

那么我如何才能访问他们应用的捆绑标识符?

谢谢

【问题讨论】:

    标签: ios swift frameworks bundle-identifier


    【解决方案1】:

    这很容易。

    每种类型(类或结构)都知道它与哪个捆绑包相关联。

    Step 1# 获取框架内任意对象的类型。

    步骤 2# 获取该类型的捆绑包。并访问它的 id。

    // VC is ref to the class object of the main app
    
    // # 1 -> This will give the class type of the object
    let objectType = type(of: vc) 
    
    // # 2 -> This will get you the bundle of the main app
    let bundle = Bundle(for: objectType.self)
    
    // This will finally give you the bundle id
    let bundleId = bundle.bundleIdentifier
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 2011-10-20
      • 1970-01-01
      相关资源
      最近更新 更多