简体   繁体   English

如何在IOS 5及以上版本中找到最前端应用的紫色端口?

[英]How to find the purple port for the front most application in IOS 5 and above?

I am trying to write an app that runs in the background and injects touches to the springboard or other apps. 我正在尝试编写一个在后台运行的应用程序,并为跳板或其他应用程序注入触摸。 I understand that I will be using private APIs and structures. 我知道我将使用私有API和结构。 The app is an enterprise app and does not need to be approved for the AppStore. 该应用程序是一个企业应用程序,无需批准AppStore。

I am using the GSEvent structure as suggested by KennyTM with some minor modifications for IOS 5/6. 我正在使用KennyTM建议的GSEvent结构,对IOS 5/6进行一些小修改。 I am able to send touch events and other events to the Springboard by sending GSSystemEvents. 我可以通过发送GSSystemEvents将触摸事件和其他事件发送到Springboard。

I need to be able to send similar events to other applications as well, but I am not able to find the port for the front most application. 我需要能够将类似的事件发送到其他应用程序,但我无法找到最前面的应用程序的端口。

Is there a way to get the port for the application that is upfront and running so that I can send my GSEvents to the app? 有没有办法获得前期和运行的应用程序的端口,以便我可以将我的GSEvents发送到应用程序?

It would be nice if someone can point me to examples or show me how I can get the purple port of the front most app. 如果有人可以指出我的例子或告诉我如何获得最前端应用程序的紫色端口,那将是很好的。

Thanks! 谢谢!

UPDATE: I haven't tested this on ios7. 更新:我没有在ios7上测试过这个。

I happen to work on the exact same requirement before. 我之前碰巧完全按照相同的要求工作。

To get the purple port, you can use GSCopyPurpleNamedPort() with the bundle Id as an argument. 要获取紫色端口,可以使用GSCopyPurpleNamedPort()并将包ID作为参数。

If you need to simulate touch on SpringBoard, use GSGetPurpleSystemEventPort. 如果需要在SpringBoard上模拟触摸,请使用GSGetPurpleSystemEventPort。

With this below code, you should be able to get the port and use it to inject touch system wide. 使用下面的代码,您应该能够获得端口并使用它来注入触摸系统。

#import <dlfcn.h>
// Framework Paths
#define SBSERVPATH  "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"
-(mach_port_t)getFrontMostAppPort
{
    bool locked;
    bool passcode;
    mach_port_t *port;
    void *lib = dlopen(SBSERVPATH, RTLD_LAZY);
    int (*SBSSpringBoardServerPort)() = dlsym(lib, "SBSSpringBoardServerPort");
    void* (*SBGetScreenLockStatus)(mach_port_t* port, bool *lockStatus, bool *passcodeEnabled) = dlsym(lib, "SBGetScreenLockStatus");
    port = (mach_port_t *)SBSSpringBoardServerPort();
    dlclose(lib);
    SBGetScreenLockStatus(port, &locked, &passcode);
    void *(*SBFrontmostApplicationDisplayIdentifier)(mach_port_t *port, char *result) = dlsym(lib, "SBFrontmostApplicationDisplayIdentifier");
    char appId[256];
    memset(appId, 0, sizeof(appId));
    SBFrontmostApplicationDisplayIdentifier(port, appId);
    NSString * frontmostApp=[NSString stringWithFormat:@"%s",appId];
    if([frontmostApp length] == 0 || locked)
        return GSGetPurpleSystemEventPort();
    else
        return GSCopyPurpleNamedPort(appId);
}

I've tested...this works fine on iOS 5 and 6. You might not need the lock part if you don't inject when the lock screen shows up. 我已经测试过...这在iOS 5和6上工作正常。如果你在锁定屏幕出现时没有注入,你可能不需要锁定部分。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在调整应用程序中将UIView添加到整个iOS的最前面的视图? - How to add an UIView to the front most view of the whole iOS in the tweak application? 如何从iOS中的SpringBoard调整中获取最前面的应用程序的实例(UIApplication)? - How to get the instance(UIApplication) of the front most application from SpringBoard tweak in iOS? 无论iOS 7(Jailbroken)中哪个应用程序位于最前端,如何为整个屏幕截取屏幕截图 - How to take screenshot for the entire screen no matter which app is at front most in iOS 7(Jailbroken) 是否可以将 iOS 应用程序移植到 Android? - Is it possible to port an iOS application to Android? 在iOS按钮上方显示小动画的最有效方法? - Most efficent way to show a small animation above a button in ios? iOS应用程序允许在应用程序边界上方滚动 - iOS app allows scroll above application boundaries 在iOS路径上方的哪里可以找到? - where can i find above iOS path ? 如何找到iOS应用程序的播放音​​频路径? - How to find play audio path for iOS application? 如何在iOS应用程序中找到内存压力的来源 - How Find the Source of Memory Pressure in an iOS Application iOS a:访问的链接显示默认的紫色 - iOS a:visited link showing default purple color
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM