So you want to write Cydia tweaks for iOS? Read This.


This post is aimed at people who want to write Cydia tweaks, or anything really, but don’t know anything about programming at all.

Everybody wants to write something for iOS. Some will opt to write apps, others prefer to do open development writing  tweaks, Siri enhancements, notification center widgets, and the like. Some of us can actually write both. It is undoubtedly that many people want to develop something for iOS, and they cannot be blamed. iOS is a wonderful mobile OS, it has many powerful features, and in the end, developers, whether they write “official apps” or tweaks, help make the platform better. So many tweaks have been so great, that Apple actually hired some people that wrote certain tweaks so they could officially extend the platform with them. Writing for iOS is something a lot of developers want to do, and many of them help make it better one of the best mobile OSes ever created.

All kinds of people have been attracted to the platform. Middle schoolers, high schoolers, college students, professionals who are not necessarily linked to the IT industry… Everyone seems to have a breathtaking idea of what to do for the platform. But here’s the thing; many of them have no idea of what to do. Out of all the people who have great ideas, many of them just hire a development company to bring their ideas to life. Others are willing to take the whole thing in their own hands. In this article, I want to focus in the latter people, particularly in those who have decided to go the jailbreak way.

I don’t want to discourage anyone from trying to bring their own ideas to life (although, it may look that way): In fact, it is the other way around. But the truth is that many people who attempt to write something for Cydia, have no idea of what to do. They don’t know where to begin, they don’t know how long it will take them or how long it should take them. In this article, I hope to clarify some doubts of that type that interested people may have.

The truth is that, ever since I started writing jailbreak tutorials, a lot of people have wanted to jump into the Tweaks bandwagon and have asked me questions. I don’t mind if people ask me questions; I love helping people and I love teaching, that’s why I write tutorials after all, but I always expect people who contact me to have a little bit of experience writing code for iOS (or at least a good amount of experience in any programming language). When I’m starting to help someone who sends me a tweet or comments on my blog, I always assume they will be able to understand my answer because they have enough technical knowledge to absorb it all and use it. But many times people who have never written any line of code in their lives ask me about Tweak development. This astonishes me, it really does, because you can’t have no experience with programming and expect to have a working tweak from night to morning. Jumping to tweak development as your first project is NOT a good idea. There’s many steps you have to go through before you try to do something like that. Of course, I don’t mind if people ask me, “hey, I’m completely new to programming but I want to write tweaks for Cydia. Can you tell me where should I begin”, I will happily give them pointers to start out, but just that, tips to start out. With the pointers I give to complete beginners they will not be able to, nor should they attempt to, write a full working piece of code in a very short time.

If you are a new programmer with limited experience, or if you are someone who has never written code in their life (note: CSS and HTML do not count as programming languages because there is no actual programming logic involved), then you need time. This is really, really important. You need a lot of time and dedication. I know, it sucks, you saw this guy writing a MobileSubstrate tutorial that is easy to follow and he creates a working example and you expected to make it work as the first code you write, but later you realise that you need to know many more things if you actually want to write tweaks; or, you are trying to run the examples, but you get errors you do not understand, so then you are disappointed you need to invest a lot of time learning many more things. I reiterate, even if your biggest dream is to get your tweak up and running on Cydia, you just cannot jump into it if you don’t know programming – many things can and will go wrong.

Programming is not for everyone. It really is not. I see people who love programming, and I see people who hate it, but I never see people in the middle of these two extremes. How can you tell if you like programming or not? You may be asking yourself that important question right now. The answer is really simple: You try to learn it and do it. If you are not enjoying it, then stop right now and find the right vocation for yourself that will make you live happily for the rest of your time. If you like it, then congratulations! You may be in the right path to code your dreams into reality. But how do you learn, you say? This is actually a complicated question. There are many ways you can learn programming. You can go to classes, either in college or otherwise, you can buy books and go the self-taught path, or you can try something more dynamic like http://www.codecademy.com. Personally, I am self taught (and this tutorial will go around my experience), and I can definitely tell you that you can teach yourself programming by buying books and practicing on your own. Actually, I am a slow learner; to the day I have problems memorising my times tables, but I love programming so much, I was able to learn it on my own without having a teacher on my back saying what I should do or what I shouldn’t! And trust me, if I could do it, then you certainly can do it too.

But nothing will come out good unless you are willing to do some sacrifices. Once on Quora.com, I saw someone asking how can a slow learner learn to program? and I wrote a lengthy answer, but that answer can be shortened into very few words: Get time, get interest, and get resources. First, you really need to invest a lot of time if you want to write code. You may have to sacrifice many things and hobbies if you really like it a lot; You will need to spend less time with your friends and more time with yourself. You will need to kill some time of your hobbies (in my case, anime and video games) to make more time room for your programming. If you think “5 minutes for programming a day” is enough to become “good” at it, then you don’t have the right mentality. You must be willing to spend hours learning programming a day, and actually programming when you get the hang of it. You must also have enough self-discipline to read books without getting distracted (if you are going the self taught way, of course), and you must be prepared to read technical books and resources, lots of them (it was hard for me, because I am a fantasy lover, but now I can read all kinds of books with no problems so learning to program paid off for more things than just programming). You will not reach your final goal of writing tweaks or apps people will use if you don’t make time for a decent of programming in your schedule a day. How you get your books is not a concern of mine, but most of the time you will need money to buy them, too (I will tell you about the books I used to learn later, first come the words of encouragement!)… If you are focused on your goal, some sacrifices are due.

Second, you need to love it. Like I said earlier, if you can’t sit still writing and reading then programming is not for you. If you don’t have enough interest in programming, then find something else you love doing. Programming, like many other vocations and even hobbies, is something you have to love in order to do it right. Even if you are “good” at programming “naturally”, if you are not enjoying it you will be as bad as someone who doesn’t know what HTML is. You have to find programming interesting. The good news is, even if you think it’s boring, you can find an use for it! Maybe you are a musician right now who wants to write a guitar app or a SpringBoard Tuner tweak, but you don’t think you find programming interesting enough. Programming can solve many needs. Programmers are usually multi-talented people (I’m not saying we are the wisest of men, but rather we do have knowledge in lots of things because we solve all sorts of problems via code). When we write code, we enhance our knowledge for things. A programmer can be asked to write a running algorithm and in the way he will learn about music; the musician wanting to learn programming will be able to learn programming not only for app or tweak, but to solve other problems that will arise in the future for him or her as well. If you think programming is not for you, think on the kind of problems you could solve when doing your other hobbies or works: It will certainly pay off very well!

Finally, get resources. You may be a Computer Science student who goes to programming classes. But why limit yourself to that when you can learn a lot more beyond the scope of your classes? Try to get your hands in books of programming topics that interest you, or at least browse the web for articles and tutorials. The internet actually has many nice tutorials and articles for any programming-related topic you may think of. If you are self taught, you should definitely go to your local library and browse the sections where programming books can be found. Maybe a nifty title will grab your attention and you may want to buy it. Libraries are beautiful places to look for resources. Where I live, we don’t have many libraries, but when I go the USA, I can spend hours and hours browsing the books in Barnes & Noble until I find something I like or reading the first chapter of a book that calls my attention. You should definitely do this too. It sounds boring, specially if you are a school teacher. But if you are really into programming and you find it fascinating, it should be as easy as pie as to browse books just like that. You learn a lot that way, even by just looking at book titles.

Are you still with me? If you are still reading this, I assume you recognise that you won’t write the next breathtaking tweak in one night, and that you are willing to spend a lot of time learning your way to success. If you are discouraged, I’m sorry, you may want to stop reading this now. But if you are with me, willing to invest time and do the needed sacrifices, then keep reading, this is where things get a little better.

Alright, so now you may actually want me to give you some resources, and tell you about how I got here. You see, like I said before, I am entirely self taught. I have taken programming classes in college because they were a requirement, but honestly I learned very little stuff that can be applied to my daily routine. The first code I was exposed to in my life was HTML. I learned HTML, CSS, and JavaScript. Then I wanted something more challenging, and wanted to learn PHP and C++. PHP is completely unrelated right now so I will tell you about my experience with C++. First I went to a website called http://www.cplusplus.net (great site, by the way) to look for my first C++ tutorials. Honestly, at first I tried to follow the tutorial, but I had no idea of what I was doing, nor did I understand what was going on, despite the fact that I read the same tutorials many, many times. My head could not absorb those concepts at all, so I was discouraged and I just said “meh, I will wait till college teaches me all this”. This was when I was 14. We went to the USA for vacation that year, and we walked into a Barnes & Noble store and I was fascinated by all the books I could see. I saw a C++ book that called my attention, in January like 3 days after new years. The book was called “C++ Without Fear”. The monster in the cover made me think that programming maybe is easier to understand than what I think, and I thought the monster in the cover made the book look like it was easy to understand. So I brushed off some 50$ and bought that book. It was the first programming book I had ever purchased. When we returned home with my family from the US, I started reading the book.

C++ Without Fear Cover.

And boy was I impressed! Things started to make sense, with the way that book explained things. I ate this book in a few books and I was much better at C++ (nowhere near an expert, and I still didn’t know half of the language, but it gave me the first foundations to study C++ a bit more). “C++ Without Fear” is a book I recommend to anyone who wants to learn programming. It may look ridiculous, it may look easy, but it does a very great job teaching the noob programmer how to do things right. The book is of course, incomplete; C++ is a huge language that is really hard to cover completely from top to bottom. I was also using a Windows Machine back then. The CD that comes with the book has Windows software and it can’t be used in a Mac. Regardless, I recommend this book to anyone who wants to learn programming because of its way of explaining things. C++ is a language, so the language itself, you can learn it on any machine running any OS. If you want to get this book, you can follow the examples by using Xcode on your Mac, without tinkering with the examples to make them work in OS X.

As a complementary book for C++, you can buy, and I recommend “Professional C++” by Solter and Kepler. This book, like its name may imply, focus on C++ at a much complex level, because it doesn’t teach you the basics anymore. It teaches you other languages features like templates and the such.

Professional C++ Book Cover

Why C++ when there are only Objetive-C and C frameworks in Cocoa/Cocoa Touch, you say? C++ is really powerful. C++ is not a hard language, but it certainly is one of the most complex languages out there. If you can pick C++ up with most of its features, learning other languages may be a bit easier. Also, a big advantage of C++ over C is that C++ offers the Object-Oriented programming paradigm; Objective-C is entirely an Object-Oriented language, so if you pick C++’s object oriented features, with a solid grasp of Object Oriented Programming (OOP), then you will have an easier time picking up Objective-C.

A book I have checked out that looks great is called “Learning C On The Mac”. This may, or may not be, a better book to learn programming on your Mac, It teaches you C and it explains things nicely, so if you want to pick C over C++ before going to Objective-C this book is not bad all. Only bad thing is that C itself has no OO capabilities so depending on the person, picking up Objective-C may be a tiny little bit harder to pick than someone who already picked it up with C++.

Learning C On The Mac Cover

Once you learn C or C++, you have to learn Objective-C. Objective-C is (like you may have been able to deduce) the main language used to create Mac and iOS applications. The de-facto book to learn Objective-C is Stephen Kochan’s “Programming In Objective-C 2.0”. This is the only Objective-C book I have ever read. It’s so complete I don’t think you need to learn anything else.

Programming Objective-C 2.0 Cover

Then you have to learn Cocoa Touch, the framework for iOS apps. There’s many books for this topic that I have read and all of them contributed to what I know about iOS development. The Big Nerd Ranch’s book iPhone Programming is a great book for iOS programming, praised by many people, and one of the most complete and well explained iOS books out there. Apress has published many iOS books. The ones I have read that I think are good are “Beginning iPhone Development: Exploring the iPhone SDK”, which teaches a little bit of Objective-C at first but later is fully iPhone-Oriented. I have read this book for iOS 4 and iOS 5 and it’s really neat. As additional books, Erica Sadun’s “The iOS Developers Cookbook” is a must have. Erica is a recognised developer and her books are neat, not to mention she hosts her examples on her Github so you can tinker with them.

The iOS 5 Developers Cookbook.

Now, why all the official development books even though this article is focused on tweaks, you say? Because it will be really hard to write your tweaks without knowing any of these material! If you want to write a tweak that shows an alert view, you will need to know how to create the alert view. The Cocoa frameworks, which you will learn about them with those “learning iOS dev” books I showed you above  is essential for you to do anything. Yes, you can mix C and C++ code, even manipulate C++ and C strings if you prefer to over Objective-C, but the Foundation’s framework NSString can make your life easier. Also all the UI elements for iPhone are written using Objective-C frameworks, so you must understand all the material in those earlier books.

An additional book, but a book I have skimmed over a few times and looks really good, is “Hacking and Securing iOS Applications” by Jonathan Zdziarski. This book is important for both tweak developers and official developers, because this book shows exploits, how to find security holes, and how to abuse them. It looks like a wonderful every iOS developer should read, and it can benefit everyone equally.

Hacking and Securing iOS Applications Cover

A final resource will always be Apple’s Developers website (developer.apple.com). You must learn to use this reference for the official frameworks.

Now to talk a bit more about Cydia tweaks and jailbreak apps, this is really a vast topic. Private frameworks change a lot in each iOS release. All the knowledge you will get up to this point will help you more doing tweaks. For iOS tweaks, you will browse private headers a lot. You will need to learn to get your hands in these private framework headers (some people share them, others dump their own). Dumping them on your own is not hard, but it takes a while to fix the headers yourself (because they are not always compile-ready). Then you will learn to “hook code” and a basic knowledge on the Objective-C’s runtime (which is something every developer should learn, not only jailbreak people) so you have a basic understanding of code hooking and how C really works with your C++ code. There are not many books dedicated to iPhone development (Jonathan Zdziarski has written one, but it hasn’t been updated since 2008 and it still focuses on iOS 2.0; iOS 6 is just around the corner now). Your patience will be tested, trust me. You will experiment a lot with code to learn what is it that you should hook and what you should leave alone. You may need to restore your device more than once in some cases. Open development can be really tough if you don’t know what you are doing; you can damage your device if you are not careful. This is why Tweaking shouldn’t be the first thing you try to do if you are new programming altogether. You will learn a lot of iPhone headers, and you will get used to research because like I said, the private frameworks change a lot in each iOS release, so  your iOS 5 tweak that works wonderfully, that took you months to develop, may break on iOS 6 and you will need to find the alternative way to hook your code.

Okay, okay, woah, woah! You probably want me to stop for a little while here. I think I can hear you asking “How long is all this going to take?”. This is a very, very complicated question. Despite the fact that I have been programming for 6 years, the first thing I ever released to the public was just a few months ago. Prior to that, I spent the previous years getting programming skills for other languages and technologies. When I learned to program, the iPhone wasn’t out yet, and I actually didn’t like Apple. My knowledge was limited to web technologies, C++, and C# along with Microsoft’s technologies. I must have studied C# and Windows Development for at least a year. But I never did anything with that knowledge.

So while in my case it may have taken me 6 years to get something out, in your case it may take you more or less. It really depends on how much time and effort you put into it. But even then, then expect to have a tweak out and working in just a few months. To really understand C, you will have to do it for a pretty long time. You will end up writing lots of console/terminal programs just to learn more. If you eat absolutely all the books I mentioned (recommended), then you may be attempting to write tweak in like 9 months or so. Just learning C, you will be a few months. An extra month or so for Objective-C, and yet more time with Cocoa Touch. When you get to actual tweak development you will be exploring and researching a lot on your own or asking question in Saurik’s IRC because there isn’t much content written about iOS development.

A very important word of advice is due here: DON’T THINK ON THE TIME. Just learn programming and ENJOY YOURSELF. If you don’t, like I said, it will be evident that programming is not for you. If you focus on learning and on enjoying it, you will see that, while your tweak will still be your main goal, you will develop more programming related-goals, hopes, and dreams. You will think on other projects you want to work on, and you will get a great satisfaction of learning things.

If you have read all this and are willing to go through everything, remember to ASK QUESTIONS. On StackOverflow, on IRC channels, anywhere. Like I said, I love helping people answering their questions as long as they are interested, so send me a tweet or something if you want my help with something. I’m not an expert, there’s many things I don’t know, but part of the reason I love teaching is because I end up learning a lot. Some questions people have asked me, drove me to do some research and learn more, getting more benefit. Don’t have doubts, ever.

After all, the glory you get of releasing something to the public that people like and talk about can never be replaced by anything else. You think your tweak is not worth it? Submit it anyway: When I submitted my first tweak to ModMyi’s repo on Cydia (called SiLight, which is just a simple Siri extension that allows you to turn on your flashlight with your voice), I firstly thought no one was going to be interested on it, and that only 10 people or so would download it. You have no idea of how wrong I was: In it’s first hour, it received 70 downloads, and by the end of the day, it had 700 downloads. A tweak I thought no one was going to care was getting downloaded. The next day, I decided to Google “SiLight Siri”, and I was received by a beautiful surprise: Many blogs in many different languages were talking about that crazy flashlight you could toggle with Siri. It received a lot of praise for being “An extension that goes beyond the software and toggles the hardware”, and it received a lot of exposure. On it’s first week it received around 5000 downloads, and at the time of this writing, it has over 13000. So yes, like you can see, the effort you will put into will pay off. Even if you think your tweak is going to be ignored by everyone, you may get a very pleasant surprise when you see people downloading it, thanking you for it, using it, and talking about it. So go on! If you have spent 20 minutes of your life reading all this, I’m sure you want to have some little glory for yourself. We all do. Just remember to work hard, and don’t expect things to work out the easy way.

CHANGELOG:


August 12, 2012 at 1:00 PM [America/La_Paz]: First version of this tutorial.

Positive SSL