gpt4 book ai didi

ios - 杀死翻转开关中的应用程序

转载 作者:行者123 更新时间:2023-11-29 03:09:17 25 4
gpt4 key购买 nike

我今天使用 theos 创建了我的第一个翻转开关。

开关编辑一个 tweak 的 .plist 文件来打开它

开关工作并打开调整,但为了使调整对应用程序生效,必须重新启动应用程序

所以我需要让开关在每次打开和关闭时杀死一个特定的应用程序

顺便说一句,我是 objective-c 的新手,非常感谢您的帮助,谢谢!

我的开关.x

#import "FSSwitchDataSource.h"
#import "FSSwitchPanel.h"
#import <notify.h>
static NSString * const PREF_PATH = @"/var/mobile/Library/Preferences/file.plist";
static NSString * const kSwitchKey = @"enabled";


@interface waplastseenSwitch : NSObject <FSSwitchDataSource>
@end

@implementation waplastseenSwitch

- (FSSwitchState)stateForSwitchIdentifier:(NSString *)switchIdentifier
{
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:PREF_PATH];
id existEnable = [dict objectForKey:kSwitchKey];
BOOL isenabled = existEnable ? [existEnable boolValue] : YES;
return isenabled ? FSSwitchStateOn : FSSwitchStateOff;
}

- (void)applyState:(FSSwitchState)newState forSwitchIdentifier:(NSString *)switchIdentifier
{
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:PREF_PATH];
NSMutableDictionary *mutableDict = dict ? [[dict mutableCopy] autorelease] : [NSMutableDictionary dictionary];
switch (newState) {
case FSSwitchStateIndeterminate:
return;
case FSSwitchStateOn:
[mutableDict setValue:@YES forKey:kSwitchKey];
break;
case FSSwitchStateOff:
[mutableDict setValue:@NO forKey:kSwitchKey];
break;
}
[mutableDict writeToFile:PREF_PATH atomically:YES];
notify_post("Flipswitch.settingschanged");
}

@end

最佳答案

我用它来解决

 system("killall -9 AppName");

像这样

case FSSwitchStateOn:
[mutableDict setValue:@YES forKey:kSwitchKey];
system("killall -9 AppName");
break;
case FSSwitchStateOff:
[mutableDict setValue:@NO forKey:kSwitchKey];
system("killall -9 AppName");
break;

干杯!

关于ios - 杀死翻转开关中的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22390049/

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