How to use CFPreferencesAppSynchronize with ARC and non ARC (iOS8 Tweaks) + CFNotificationCallback (option) Works fine with Sandbox Apps
| 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