gpt4 book ai didi

ios - 将 App Delegate 与 MobileSubstrate Hook 以将新方法添加到所有应用程序中

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:14:59 25 4
gpt4 key购买 nike

我正在使用 Logos 构建一个 MobileSubstrate 调整,并且我正在尝试添加一种新方法来将设备锁定到设备上的每个应用程序中,这将在接近更改通知后运行。到目前为止,我的代码是

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <SpringBoard/SpringBoard.h>
#import <SpringBoard/UIApplicationDelegate.h>
#import <GraphicsServices/GSEvent.h>
#include <notify.h>

@interface suspendresume : NSObject

@property(nonatomic, readonly) BOOL proximityState;

@end

@implementation suspendresume

BOOL tweakOn;

@end

static NSString *settingsFile = @"/var/mobile/Library/Preferences/com.matchstick.suspendresume.plist";

%hook SpringBoard

-(void)applicationDidFinishLaunching:(id)application {
// Allow SpringBoard to initialise
%orig;

// Set up proximity monitoring
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
[[UIDevice currentDevice] proximityState];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityChange:) name:@"UIDeviceProximityStateDidChangeNotification" object:nil];
}

%new

// Add new code into SpringBoard
-(void)proximityChange:(NSNotification*)notification {
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];

// Check if tweak is on
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:settingsFile];
tweakOn = [[dict objectForKey:@"enabled"] boolValue];

// Only run if tweak is on
if (tweakOn) {

// Get first proximity value
if ([[UIDevice currentDevice] proximityState] == YES) {

// Wait a few seconds TODO allow changing of wait interval from prefrences FIXME causes a lockup of interface whilst sleeping
[self performSelector:@selector(lockDeviceAfterDelay) withObject:nil afterDelay:1.0];
}
}
}

%new

-(void)lockDeviceAfterDelay {

// Second proximity value
if ([[UIDevice currentDevice] proximityState] == YES) {

// Lock device
GSEventLockDevice();
}
}

%end

这在 SpringBoard 中按我的要求工作,但在设备上安装的任何其他应用程序中都没有 - 测试时发生的所有事情是当接近传感器被触发时显示器关闭,并且不会锁定设备。

我正在考虑使用 UIApplicationDelegate 的-(void)applicationDidFinishLaunching:(id)applicationUIApplication 在应用程序中实现与我使用 SpringBoard 时相同的效果,但不知道如何做到这一点。

这种方法的想法来自 from this project

我是否需要将在 SpringBoard 中运行的相同代码添加到 UIApplication 下的新方法中?

我是否需要为每个应用程序重新设置接近度监控,以及在收到接近度更改通知后如何调用这些新方法来运行?

另外,full source for this is on my GitHub

最佳答案

结果证明这不是正确的方法。相反,

// Get the topmost application
SBApplication *runningApp = [(SpringBoard *)self _accessibilityFrontMostApplication];
// We're in application, resign app
[runningApp notifyResignActiveForReason:1];

成功了。

关于ios - 将 App Delegate 与 MobileSubstrate Hook 以将新方法添加到所有应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15589336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com