i am writing my first tweak for iOS using theos and I am stuck at optimization.As i can see,dylib will check every time(every second?) "([[settings objectForKey:@"something"] boolValue])" and "[[settings objectForKey:@"SomethingHere"] boolValue]" in plist file.
Is it OK? Any suggestion for optimization? Here is my tweak :
%hook Something
- (void)somethingheree:(_Bool)arg1 withNumberOfDevices:(int)arg2
{
NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithContentsOfFile:
[NSString stringWithFormat:@"%@/Library/Preferences/%@", NSHomeDirectory(), @"com.yourcompany.mytweak.plist"]];
if([[settings objectForKey:@"something"] boolValue]) {
%orig(YES,100);
}
else %orig;
}
%end
%hook somethinganother
- (void)somethinghere:(_Bool)arg1
{
NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithContentsOfFile:
[NSString stringWithFormat:@"%@/Library/Preferences/%@", NSHomeDirectory(), @"com.yourcompany.mytweak.plist"]];
if([[settings objectForKey:@"SomethingHere"] boolValue]) {
%orig(NO);
} else %orig;
}
%end
If you are using PreferenceLoader for your preferences panel, you can save the value in a global variable and use darwin notifications to monitor the changes of preferences. You can find a lot examples in open source tweaks, such as one of mine:
https://github.com/Qusic/MailtoOpener/blob/master/Tweak.mm#L192