2

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?

clemens
  • 16,716
  • 11
  • 50
  • 65
nehaSingh
  • 71
  • 1
  • 7

1 Answers1

5

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.

clemens
  • 16,716
  • 11
  • 50
  • 65
  • how do we use class dump, I am not able to understand the same. – nehaSingh Mar 23 '18 at 06:55
  • @nehaSingh: I've extended my post. – clemens Mar 23 '18 at 07:44
  • I used the following code to access teh bundle at the given path it it gives nil. NSBundle *bundle = [NSBundle bundleWithPath:@"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks"]; if (![bundle load]) { NSLog(@"Error"); // maybe throw an exception } else { _supporter = [NSClassFromString(@"BCBatteryDevice") valueForKey:@"sharedInstance"]; _handler = [[BCBatteryDeviceHandler alloc] init]; } – nehaSingh Mar 23 '18 at 11:52
  • @nehaSingh: Your path doesn't point to a valid framework bundle. Please see my post above.The frameworks in the SDK directory doesn't contain a valid binary. The just contain .tbd files which can neither be loaded nor inspected by class dump. – clemens Mar 23 '18 at 14:22
  • BatterCenter.Framework does not exist at the given path : /System/Library/PrivateFrameworks , – nehaSingh Mar 26 '18 at 04:51
  • @nehaSingh: 1. Its name is `BatteryCenter.framework` (case and correct spelling are important), 2. This framework exists only on **real devices**. – clemens Mar 26 '18 at 05:47