Jump to content

Code keep return %orig;


Go to solution Solved by castix,

11 posts in this topic

Recommended Posts

Posted
%hook targetClass
-(bool)istargetmethodActive{
	
	if ([[prefs objectForKey:@"keyFromPlist"] boolValue]){

		return true;

	}

	return %orig;

}
%end

I've tried running and make countless changes but the results is still the same. The problem is, when I try On or Off my tweak via Preference (in Settings app), the code keep return %orig;

 

Please help.

Posted

istargetmethodActive is case sensitive, have you copied it correctly?

 

Yes. I'm 100% sure and confident. I just want a simple workflow:

 

1. User turn the switch OFF = The tweak is not working.

2. User turn the switch ON = The tweak is working.

 

Unfortunately, nothing seems to work according my plan.

Posted


-(bool)istargetmethodActive{

 

if ([[prefs objectForKey:@"keyFromPlist"] boolValue]){

 

return true;

 

} else {

 

return %orig;

 

}

%end

Posted
-(bool)istargetmethodActive{
	
	if ([[prefs objectForKey:@"keyFromPlist"] boolValue]){

		return true;

	} else {

	return %orig;

}
%end

Got this error while processing to package... 

Tweak.xm:46: error: %end does not make sense inside a block
Posted

Forgot to close out. Set another } at the end

 

Thanks, code my code it's working now. But it seems I'm facing another problem. 

 

Quote fro Stackoverflow

 

 

 

If the key does not exist in the user defaults, the result of this method will be NO.

 

I'm facing this issue now. I think /Library/PreferenceBundles/yourtweak.bundle/yourplistname.plist  can't be read by Preference.

  • Solution
Posted (edited)

Thanks, code my code it's working now. But it seems I'm facing another problem. 

 

Quote fro Stackoverflow

 

 

I'm facing this issue now. I think /Library/PreferenceBundles/yourtweak.bundle/yourplistname.plist  can't be read by Preference.

#define kPath @"/var/mobile/Library/Preferences/YOUR_PLIST_NAME.plist"


%hook targetClass
-(bool)istargetmethodActive {
NSDictionary *prefs=[[NSDictionary alloc] initWithContentsOfFile:kPath];
%orig;
    if ([[prefs objectForKey:@"keyFromPlist"] boolValue]){
    return true;
    } else {
    return %orig;
  }
}
%end
Updated by castix

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines