How to use Springboard Services Framework to use S

2020-08-01 05:35发布

问题:

I would like to use the Springboard services framework to make use of the following code.

SBSLaunchApplicationWithIdentifier(CFSTR("com.apple.preferences"), false);

However when I download the header files and use it in my project it won't build. Please let me know how to make this work.

回答1:

What exactly are you planning on using that method for? I was under the impression it was for launching an application from a daemon?

There are other ways to launch an application quite easily. The most reliable I have found is to use the display stacks to launch the application properly. Other methods of launching the app tend to cause issues when you close it and attempt to relaunch and it crashes.

Using theos, you could do something like this:

NSMutableArray *displayStacks = nil;

// Display stack names
#define SBWPreActivateDisplayStack        [displayStacks objectAtIndex:0]
#define SBWActiveDisplayStack             [displayStacks objectAtIndex:1]
#define SBWSuspendingDisplayStack         [displayStacks objectAtIndex:2]
#define SBWSuspendedEventOnlyDisplayStack [displayStacks objectAtIndex:3]

// Hook SBDisplayStack to get access to the stacks

%hook SBDisplayStack

-(id)init
{
    %log;
    if ((self = %orig)) 
    {
        NSLog(@"FBAuth: addDisplayStack");
        [displayStacks addObject:self];
    }
    return self;
}

-(void)dealloc
{
    [displayStacks removeObject:self];
    %orig;
}

%end

And then to launch the app, do this:

id PreferencesApp = [[objc_getClass("SBApplicationController") sharedInstance] applicationWithDisplayIdentifier:@"com.apple.preferences"];

[SBWActiveDisplayStack pushDisplay:PreferencesApp];

However, if you really want to use that method, you need to specify what errors are stopping it from building and check which header files you are using to build it with. You also need to link against the SBS framework.