简体   繁体   中英

How To Import Private Frameworks to Xcode 9.2 (iOS 11) , swift

I want to test something for research purposes (not App Store!) in which I want to use the private frameworks in Xcode 9.2 (iOS 11). For that, I needed to import the private framework I want to use to my Xcode project.

But in Xcode 9.2 in folder structure private frameworks folder is not present.

Any ideas through which I can achieve that?

A private framework is just a bundle like a public framework. You can load it explicitly with:

if let framework = Bundle(path: "/System/Library/PrivateFrameworks/BatteryCenter.framework") {
    // Works only on real devices
    framework.load()
}

But you need declarations for the included classes. You might create them with class-dump as Objective C headers, and import the over a bridging header into Swift.

You execute class-dump with class-dump /.../PrivateFrameworks/XXX.framework/XXX . You need the framework as binary not as *.tbd file. Example for BatteryCenter.framework :

class-dump /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/BatteryCenter.framework/BatteryCenter

This will print you class declarations for all classes contained in the framework.

Note, on a device or a simulator you should use

/System/Library/PrivateFrameworks/BatteryCenter.framework

for loading the bundle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM