I am trying to use _CDBatterySaver to turn on low power mode simply using
[[_CDBatterySaver batterySaver] setMode:1];
I know there isn\
There's an official tool to generate .tbd
files these days, tapi
(Text-based API). Not sure when it was released exactly, but it's been around at least as long as Xcode 9.
To generate a .tbd
for a binary, you do something like the following. Here I'm using the private SafariShared.framework on OSX. If you need a .tbd
for an iOS framework, you'll have to follow the beginning of Siguza's answer to get ahold of a binary, but otherwise, the rest of this process will work.
Make an empty directory for the framework stub named, e.g., "SafariShared.framework":
$ md SafariShared.framework
Run a command like the following to generate the stub:
$ xcrun tapi stubify -o SafariShared.framework/SafariShared.tbd /System/Library/PrivateFrameworks/SafariShared.framework/SafariShared
The -o
argument is the output file and the final argument is the path to the binary (note that it is not the path to the .framework
itself; you'll get an error if you do that). Replace both as needed.
There's one potential pitfall. Stub files can contain a list of the programs that are allowed to link with that binary, and if your program isn't listed in that list, the linker will fail. Open up the .tbd
in your favourite text editor and look for lines like the following:
allowable-clients: [ , ... ]
Delete all of those (there may not be any) and save the file.
Now you're good to go! The stub .framework
directory you made in step 1 will work just like a real framework in Xcode. In your Xcode project's general settings, you can click the plus in "Linked Frameworks and Libraries" and add the stub directory.
(You may also have to add the directory containing the stub .framework
to the "Framework Search Paths" project setting. It seems flaky as to whether or not that will happen automatically.)