Last active
August 16, 2020 13:28
-
-
Save iMokhles/23061acdffbfeaa875db to your computer and use it in GitHub Desktop.
How to use CFPreferencesAppSynchronize with ARC and non ARC (iOS8 Tweaks) + CFNotificationCallback (option) Works fine with Sandbox Apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static BOOL tweakEnBOOL; | |
#define SETTINGSFILENEW "com.imokhles.Prefs" | |
#define PREFERENCES_CHANGED_NOTIFICATION "com.imokhles.Prefs.preferences-changed" | |
// non ARC | |
static void iMoLoadPreferences() { | |
CFPreferencesAppSynchronize(CFSTR(SETTINGSFILENEW)); | |
tweakEnBOOL = !CFPreferencesCopyAppValue(CFSTR("Enabled"), CFSTR(SETTINGSFILENEW)) ? YES : [(id)CFBridgingRelease(CFPreferencesCopyAppValue(CFSTR("Enabled"), CFSTR(SETTINGSFILENEW))) boolValue]; | |
} | |
// with ARC | |
static void iMoLoadPreferences() { | |
CFPreferencesAppSynchronize(CFSTR(SETTINGSFILENEW)); | |
tweakEnBOOL = !CFPreferencesCopyAppValue(CFSTR("Enabled"), CFSTR(SETTINGSFILENEW)) ? YES : [(id)CFPreferencesCopyAppValue(CFSTR("Enabled"), CFSTR(SETTINGSFILENEW)) boolValue]; | |
} | |
%ctor { | |
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), | |
NULL, | |
(CFNotificationCallback)iMoLoadPreferences, | |
CFSTR(PREFERENCES_CHANGED_NOTIFICATION), | |
NULL, | |
CFNotificationSuspensionBehaviorCoalesce); | |
iMoLoadPreferences(); | |
} | |
// and to check value within tweak. | |
// Example | |
%hook SBLockScreenViewController | |
- (void)finishUIUnlockFromSource:(int)arg1 { | |
%orig(); | |
if (tweakEnBOOL) { | |
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Unlock" message:@"your device unlock finished ;)" delegate:nil cancelButtonTitle:@"OK :)" otherButtonTitles:nil, nil]; | |
[alertView show]; | |
} | |
} | |
%end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment