Forked from iMokhles/CFPreferencesAppSynchronize with ARC and non ARC.xm
Last active
August 29, 2015 14:09
-
-
Save ichitaso/503dd22f5a4774874a52 to your computer and use it in GitHub Desktop.
This file contains 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