用于 iPhone 应用程序之间通信的 NSDistributedNotificationCenter 的替代方案

发布于 2024-12-31 21:40:11 字数 202 浏览 4 评论 0原文

我一直在寻找一种方法来实时比较同一手机上的应用程序之间的时间戳,NSDistributedNotificationCenter 听起来像是一个理想的解决方案,因为我可能不知道侦听它的应用程序的名称,但听起来它在iOS。

是否有一种等效的方法可以在不知道多个应用程序名称的情况下向其通知时间敏感事件?

针对 iOS 5+ 进行编码并假设相关应用程序将注册通知。

I've been looking for a way to compare timestamps between applications on the same phone in real time, and NSDistributedNotificationCenter sounded like an ideal solution since i may not know the names of the apps listening for it, but it sounds like its not available in iOS.

Is there an equivalent way of notifying multiple apps of a time-sensitive event without knowing their name?

Coding for iOS 5+ and assuming the apps in question will register for the notification.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

黑寡妇 2025-01-07 21:40:11

查看 /System/Library/PrivateFrameworks/AppSupport.framework 中的 CPDistributedMessagingCenter。但是,它是一个私有框架(可能会随着操作系统版本的变化而变化,并且在 AppStore 中不允许)。

这里的文档: http://iphonedevwiki.net/index.php/CPDistributedMessagingCenter

我的示例代码在这里:

https://github.com/H2CO3/PwnTube

https://github.com/H2CO3/Cereal

Look at CPDistributedMessagingCenter in /System/Library/PrivateFrameworks/AppSupport.framework. However, it's a private framework (may change with OS releases, and not allowed in AppStore).

Documentation here: http://iphonedevwiki.net/index.php/CPDistributedMessagingCenter

Example codes of mine here:

https://github.com/H2CO3/PwnTube

https://github.com/H2CO3/Cereal

风为裳 2025-01-07 21:40:11

我很确定你可以使用 Mach 端口。它们的级别有点低,但效果很好。

I'm pretty sure you can use Mach ports. They are a bit low level but work well.

梅窗月明清似水 2025-01-07 21:40:11

我找到了一种在 iOS 上使用 CFNotificationCenterGetDistributedCenter() 的方法。它存在于设备上,但在 iOS SDK 中不导出

void *libHandle = dlopen("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", RTLD_LAZY);
CFNotificationCenterRef (*CFNotificationCenterGetDistributedCenter)() = (CFNotificationCenterRef (*)())dlsym(libHandle, "CFNotificationCenterGetDistributedCenter");
if(CFNotificationCenterGetDistributedCenter) {
    CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), NULL, &NotificationUpdateApp, CFSTR("TestApp"), NULL, CFNotificationSuspensionBehaviorCoalesce);
}
dlclose(libHandle);

i found a way to use CFNotificationCenterGetDistributedCenter() on iOS. It is exists on device, but not exports in iOS SDK

void *libHandle = dlopen("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", RTLD_LAZY);
CFNotificationCenterRef (*CFNotificationCenterGetDistributedCenter)() = (CFNotificationCenterRef (*)())dlsym(libHandle, "CFNotificationCenterGetDistributedCenter");
if(CFNotificationCenterGetDistributedCenter) {
    CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), NULL, &NotificationUpdateApp, CFSTR("TestApp"), NULL, CFNotificationSuspensionBehaviorCoalesce);
}
dlclose(libHandle);
就此别过 2025-01-07 21:40:11

并不真地。在未越狱的设备上,您可以做的最接近您所要求的事情是让您的服务器与其他应用程序的服务器通信,并让该服务器向相关应用程序发送推送通知。如果没有 NSDistributedNotificationCenter(正如您猜测的那样,它在 iOS 上不可用),您实际上没有任何其他选择。

Not really. The closest you can do to what you’re asking, on a non-jailbroken device, is have your server talk to each other app’s server and have that server send a push notification to the app in question. Without NSDistributedNotificationCenter (which is, as you surmise, not available on iOS), you don’t really have any other option.

纵山崖 2025-01-07 21:40:11

这个问题有点老了,但我会发布我的答案仅供参考。

NSDistributedNotificationCenter 尚不适用于 iOS,除非您正在开发一个不会假装在 AppStore 上发布的应用程序,否则您不能使用 AppSupport.framework,因为它是私有的。

iOS8 发布了应用程序扩展,使我们能够与其他应用程序进行通信。我不知道你到底想做什么,但我相信,如果你只是想比较其他应用程序的一些时间戳,它应该可以解决你的问题。

AppExtensions 文档链接:
https://developer.apple.com/library/ios/documentation/ General/Conceptual/ExtensibilityPG/

希望它对某人有帮助。

This question is a little bit old, but I'll post my answer just for information purposes.

NSDistributedNotificationCenter is not available for iOS yet, and unless your are developing an app that you don'd pretend to release on AppStore, you can't use AppSupport.framework because it's private.

iOS8 released App Extensions, that give us the ability to communicate with other apps. I don't know what you are trying to do exactly but I believe that if you are just trying to compare some timestamps from some other apps, it should resolve your problem.

Link to AppExtensions documentation:
https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/

Hope it helps somebody.

找回味觉 2025-01-07 21:40:11

NSDistributedNotificationCenter 存在于 iOS 上,但标头不提供给开发人员。

使用以下内容在项目中创建一个头文件以使该类可用:

@interface NSDistributedNotificationCenter : NSNotificationCenter

+ (NSDistributedNotificationCenter *)defaultCenter;
// Returns the default distributed notification center - cover for [NSDistributedNotificationCenter notificationCenterForType:NSLocalNotificationCenterType]

- (void)postNotificationName:(NSNotificationName)name object:(nullable NSString *)object userInfo:(nullable NSDictionary *)userInfo deliverImmediately:(BOOL)deliverImmediately;

@end

当尝试从应用程序获取信息到其 UITest 运行程序时,这非常有用,但显然您不应该尝试将其放入应用商店。

我创建了一个项目 XCTestBackChannel 来展示这一点。

NSDistributedNotificationCenter exists on iOS, but the headers aren't made available to developers.

Create a header file in your project with the following to make the class available:

@interface NSDistributedNotificationCenter : NSNotificationCenter

+ (NSDistributedNotificationCenter *)defaultCenter;
// Returns the default distributed notification center - cover for [NSDistributedNotificationCenter notificationCenterForType:NSLocalNotificationCenterType]

- (void)postNotificationName:(NSNotificationName)name object:(nullable NSString *)object userInfo:(nullable NSDictionary *)userInfo deliverImmediately:(BOOL)deliverImmediately;

@end

This is very useful when trying to get information from an App to its UITest runner, but you should obviously NOT attempt to put this in the AppStore.

I've created a project XCTestBackChannel to show this off.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文