Lucas Jackson / November 13, 2016

Writing a Cydia Tweak for Tinder

Star Download

Overview

One day while driving, I looked over and saw a guy struggling to keep control of his steering wheel while swiping through possible soul mates. At first I thought, what an idiot, then I was like, if you used 1 hand to hold the phone and swipe, you could use the other hand to use the steering wheel, giving this guy a 50% better chance of not crashing. And so I bring you tinder+-, the first tweak that lets you swipe left and right with your volume buttons! Below are the steps on how to create/write this tweak.

Finding functions to hook

Writing a tweak really isn’t that hard if you have Objective-c programming experience. Clutch was used to decrypt the tinder binary on the jailbroken iOS device. I then used class-dump to dump the header files to search for what methods I would be hooking into.

After a quick search for “swipe” I find our class we are looking for, TNDRRecommendationViewController

Writing our tweak

So knowing our 2 functions that need to be called, “notifyInteractionHandlerOfSwipeRight” and “notifyInteractionHandlerOfSwipeLeft”, we now have a basic idea of what to do. The goal is to try and detect volume changes, disable the HUD display when volume is changed, and call our notifyInteractionHandler function when volume change is detected. To write this tweak we are going to use Theos, a popular make file platform that is commonly used to write cydia tweaks. To start a project we use “nic”, included in theos. On Theos for OS X, nic is located at /opt/theos/bin/nic.pl.

The steps for setting up our project are pretty straight forward We will choose 11 for creating a tweak, set our project name, and when we are prompted for “MobileSubstrate Bundle filter” we will enter “com.cardify.tinder” which is the bundle id for the app we are tweaking

Our project directory tinderplusminus is then made and should look something like this.

Our code for our tweak will be located in Tweak.xm. Tweak writing in theos uses a component called Logos. It gives us everything we need to change the way an app will perform. In Tweak.xm, we will use %hook, %orig, %new, and %end to tweak tinder functions. Below is the very first coding step to tweaking. To hook into TNDRRecommendationViewController all we have to do is use %hook.

			//hook into TNDRRecommendationViewController
			%hook TNDRRecommendationViewController
			
			//end of hook
			%end
			
			//we hook multiple classes in a single file too, just make another "%hook classname" and "%end"            
						

TNDRRecommendationViewController is of class type “UIViewController”. We can modify a function by writing it between %hook and %end. Use %orig where you want to keep the function’s original code. Below we modify the viewDidLoad function and display an alert when TNDRRecommendationViewController’s view is loaded.

			//hook into TNDRRecommendationViewController
			%hook TNDRRecommendationViewController
			- (void)viewDidLoad {
			    %orig;
			    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello, World"
			        message:@"We hooked into TNDRRecommendationViewController and modified viewDidLoad!"
			        delegate:self
			        cancelButtonTitle:@"Dismiss"
			        otherButtonTitles:nil];
			    [alert show];
			    [alert release];
			}
			%end

To compile, we run “make package” in our project directory and a deb will be generated in the “packages” directory

To test our tweak, transfer our deb over (I recommend using SSH) and run “dpkg -i pathtotweak.deb; killall SpringBoard” on your iDevice. And when we open tinder, we can see our code was successfully run!

The next step is to detect volume up or down presses. In our tweak we can import Frameworks, just like in Xcode. For this tweak I used the frameworks MediaPlayer and AVFoundation. To detect volume presses, I compared volume changes with the previous volume. the comparison function uses %new to create a new function within the class we are hooked into. When we are hooked into a class, we can call any function that is defined in that class. Below we can call swipe left or swipe right wherever we desire.

			%new
			-(void)newfunction {
			    //swipe right
			    [self performSelector:@selector(notifyInteractionHandlerOfTapRight)];
			    //swipe left
			    [self performSelector:@selector(notifyInteractionHandlerOfTapLeft)];
			}

Not going into programming details, thats what stack overflow is for ;). Below is the tweak.xm file used in tinder+-. I have commented the code so it shouldn’t be that hard for those of you reading to use this tutorial and use it to start creating your own tweaks.

			//Created by Lucas Jackson
			//Tinder+-
			//October 2016
			#import <MediaPlayer/MediaPlayer.h>
			#import <AVFoundation/AVFoundation.h>
			
			%hook TNDRRecommendationViewController
			
			MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame: CGRectZero];
			UISlider *volumeViewSlider = nil;
			bool isChanging = false;
			
			//override existing function by writing them here
			//all other functions still exist even though they aren't written
			- (void)viewDidLoad {
				%orig;
				
				//show an alert cause we can
				UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tinder+-"
			    	message:@"Use up volume to like, down volume to pass... or keep holding one down to have some fun ;)"
			        delegate:self
			        cancelButtonTitle:@"Dismiss"
			        otherButtonTitles:nil];
				[alert show];
				[alert release];
				
				//disable HUD displaying using custom view (preset frame to CGRectZero ^)
				UIView *hudview = [(UIViewController *)self view];
				[hudview addSubview:volumeView];
			
				//get volume slider so we can change system volume
				for (UIView *view in [volumeView subviews]){
					NSString *className = NSStringFromClass([view class]);
				    if ([className isEqualToString:@"MPVolumeSlider"]){
				        volumeViewSlider = (UISlider*)view;
				        volumeViewSlider.value = 0.5;
				        //listen for volume changes
				        [volumeViewSlider addTarget:(UIViewController *)self action:@selector(didchangevolume) forControlEvents:UIControlEventValueChanged];
				        break;
				    }
				}
			}
			
			//we can use %new to create new functions in this class
			
			%new
			-(void)didchangevolume {
				//prevent loop of death
				if (isChanging) {
					return;
				}
				
				//based on the difference from 0.5 we can decide weather it was a down volume press, or an up volume press	
			
				isChanging = true;
				if (volumeViewSlider.value > 0.5) {
					//swipe right function
					[self performSelector:@selector(notifyInteractionHandlerOfTapRight)];
					volumeViewSlider.value = 0.5;
				}
				else if (volumeViewSlider.value < 0.5){
					//swipe left function
					[self performSelector:@selector(notifyInteractionHandlerOfTapLeft)];
					volumeViewSlider.value = 0.5;
				}
				isChanging = false;		
			}
			
			%end

In the makefile I have specified the frameworks I used, MediaPlayer and AVFoundation.

			include $(THEOS)/makefiles/common.mk
			
			TWEAK_NAME = TinderPlusMinus
			TinderPlusMinus_FILES = Tweak.xm
			TinderPlusMinus_FRAMEWORKS = MediaPlayer AVFoundation
			include $(THEOS_MAKE_PATH)/tweak.mk
			
			after-install::
				install.exec "killall -9 SpringBoard"
						

compile using Xcode 7.1
sudo xcode-select -s /path/to/Xcode7.1.app

Thanks for viewing!

Source code is a available on my GitHub

Feel free to email me if you have any questions
lucasjackson5815@gmail.com