【问题标题】:How to use SpringboardServices to get notifications count of an app ios如何使用 SpringboardServices 获取应用程序 ios 的通知计数
【发布时间】:2016-08-09 11:44:46
【问题描述】:

如何使用SpringboardServicesSBSPushStore 将另一个应用的通知计数添加到我的应用中? 我正在尝试将从whatsapp获取的通知计数显示到我的应用程序中,所以我四处搜索,一件事是肯定它是可能的,但我没有找到任何认可的方法来做到这一点。
Here is the question它回答了它,但我没有得到它。怎么做?有人可以分享一步一步的过程吗。

基于这个问题,我找到了可以使用SpringboardServices 锁定您的iphone 的代码,但我不知道如何将它用于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);

【问题讨论】:

  • 该答案仅适用于越狱设备,不能在 App Store 应用中使用。这就是你想要的吗?
  • @Paulw11 没关系,我只需要展示演示。这个应用程序不会上架。所以请分享一步一步的过程,因为我是一个天真的开发者。
  • @Paulw11 在这里我找到了 SBSPushStore github.com/MP0w/iOS-Headers/tree/master/iOS5.0/…

标签: ios objective-c push-notification


【解决方案1】:

您评论的链接问题的答案暗示您不需要任何框架,只要您的设备已越狱。 您只需加载位于/var/mobile/Library/SpringBoard/applicationState.plist 的 plist 文件。该答案的格式有点错误,但我认为> 是用来解释文件内部结构(即键值)的指标。

所以我假设它是一本字典,你可以通过

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"];

您可能想先自己检查文件(因此设置一个调试点)并确保其结构与我假设的一样,类型正确等等(更不用说它存在,Apple 有时会更改类似的内容并且另一个问题已经有好几年了)。

通常请注意,如上所述,您只能在越狱设备上执行此操作。否则,您的应用程序根本没有对路径/var/mobile/Library/SpringBoard/applicationState.plist 的读取权限。或者到它的沙盒之外的任何东西,就此而言。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-25
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多