How to use SpringboardServices to get notification

2019-09-11 11:44发布

问题:

How can I get notifications count of another app into my app by using SpringboardServices and SBSPushStore? I'm trying to show notification count taken from whatsapp into my app so I was searching around and one thing is for sure that it is possible but I didn't find any approbate way on how to do it.
Here is the question which answers it but I didn't get it. How to do it? Can someone please share the step by step procedure.

Based on the question I was able to find the code which can actually lock you iphone using SpringboardServices but I don't know how to use it for SBSPushStore?

void *SpringBoardServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
    NSParameterAssert(SpringBoardServices);
    mach_port_t (*SBSSpringBoardServerPort)() = dlsym(SpringBoardServices, "SBSSpringBoardServerPort");
    NSParameterAssert(SBSSpringBoardServerPort);
    SpringBoardServicesReturn (*SBSLockDevice)(mach_port_t port) = dlsym(SpringBoardServices, "SBSLockDevice");
    NSParameterAssert(SBSLockDevice);
    mach_port_t sbsMachPort = SBSSpringBoardServerPort();
    SBSLockDevice(sbsMachPort);
    dlclose(SpringBoardServices);

回答1:

The answer to that linked question you commented on implies that you don't need any framework, as long as your device is jailbroken. You simply load the plist file located at /var/mobile/Library/SpringBoard/applicationState.plist. The format of that answer is a bit broken, but I assume the > are meant as indicators to explain the inner structure of the file (i.e. key values).

So from that I assume it's a dictionary, you can load it by

NSDictionary *plistFile = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/SpringBoard/applicationState.plist"];
NSDictionary *entryForYourApp = plistFile[@"com.app.identifier"]; // obviously you have to use the identifier of whatever app you wanna check
NSInteger badgeCount = entryForYourApp[@"SBApplicationBadgeKey"];

You probably want to inspect the file yourself first (so set a debug point) and make sure its structure is like I assumed, the types are correct and so forth (not to mention it exists, Apple sometimes changes stuff like that and the other question is already several years old).

In general be aware that you can only do that, as said, on a jailbroken device. Otherwise your application simply doesn't have reading access to the path /var/mobile/Library/SpringBoard/applicationState.plist. Or to anything outside its sandbox, for that matter.